Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya has n number segments [l1; r1], [l2; r2], ..., [ln; rn]. During one move Petya can take any segment (let it be segment number i) and replace it with segment [li + 1; ri + 1] or [li - 1; ri - 1]. In other words, during one move Petya can shift any segment to the left or to the right by a unit distance. Petya calls a number full if it belongs to each segment. That is, number x is full if for any i (1 ≤ i ≤ n) the condition li ≤ x ≤ ri is fulfilled.

Petya makes no more than k moves. After that he counts the quantity of full lucky numbers. Find the maximal quantity that he can get.

Input

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 1018) — the number of segments and the maximum number of moves. Next n lines contain pairs of integers li and ri (1 ≤ li ≤ ri ≤ 1018).

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the %I64d specificator.

Output

Print on the single line the single number — the answer to the problem.

Examples

Input

4 7
1 4
6 9
4 7
3 5


Output

1


Input

2 7
40 45
47 74


Output

2

Note

In the first sample Petya shifts the second segment by two units to the left (it turns into [4; 7]), after that number 4 becomes full.

In the second sample Petya shifts the first segment by two units to the right (it turns into [42; 47]), and shifts the second segment by three units to the left (it turns into [44; 71]), after that numbers 44 and 47 become full.
#include <bits/stdc++.h>
long long Lucky[1000024], tot;
struct BigInt {
  static const int LEN = 4;
  static const int MOD = int(1e8);
  long long a[LEN];
  BigInt(long long x = 0) {
    for (int i = 0; i < LEN; ++i) {
      a[i] = x % MOD;
      x /= MOD;
    }
  }
  BigInt& operator+=(const BigInt& o) {
    long long carry = 0;
    for (int i = 0; i < LEN; ++i) {
      carry += a[i] + o.a[i];
      a[i] = carry % MOD;
      carry /= MOD;
    }
    return *this;
  }
  BigInt operator+(const BigInt& o) const {
    BigInt c = *this;
    return c += o;
  }
  BigInt& operator=(const BigInt& o) {
    memcpy(a, o.a, sizeof a);
    return *this;
  }
  BigInt& operator-=(const BigInt& o) {
    bool borrow = false;
    for (int i = 0; i < LEN; ++i) {
      if (borrow) {
        --a[i];
        borrow = false;
      }
      if (a[i] < o.a[i]) {
        a[i] += MOD;
        borrow = true;
      }
      a[i] -= o.a[i];
    }
    return *this;
  }
  BigInt operator-(const BigInt& o) const {
    BigInt c = *this;
    return c -= o;
  }
  BigInt operator*(const BigInt& o) const {
    BigInt c;
    for (int i = 0; i < LEN; ++i) {
      for (int j = 0; i + j < LEN; ++j) {
        c.a[i + j] += a[i] * o.a[j];
      }
    }
    for (int i = 0; i < LEN; ++i) {
      if (c.a[i] >= MOD) {
        c.a[i + 1] += c.a[i] / MOD;
        c.a[i] %= MOD;
      }
    }
    return c;
  }
  bool operator<=(const BigInt& o) const {
    for (int i = LEN - 1; i >= 0; --i) {
      if (a[i] < o.a[i]) return true;
      if (a[i] > o.a[i]) return false;
    }
    return true;
  }
};
void pre() {
  for (int bit = 1; bit < 19; bit++) {
    for (int i = 0; i < 1 << bit; i++) {
      long long num = 0;
      for (int j = bit - 1; j >= 0; j--) {
        if (i >> j & 1)
          num = num * 10 + 7;
        else
          num = num * 10 + 4;
      }
      Lucky[tot++] = num;
    }
  }
}
std::pair<long long, long long> board[100010];
BigInt sum[100010];
long long minL, K;
int N;
BigInt ls[1000024], rs[1000024];
bool cmp(std::pair<long long, long long> a, std::pair<long long, long long> b) {
  return a.second < b.second;
}
int main() {
  pre();
  scanf("%d%I64d", &N, &K);
  minL = 1e18 + 1;
  for (int i = 0; i < N; i++) {
    scanf("%I64d %I64d", &board[i].first, &board[i].second);
    minL = std::min(minL, board[i].second - board[i].first);
  }
  std::sort(board, board + N);
  BigInt s = 0;
  int c = 0;
  for (int i = tot - 1, j = N - 1; ~i; i--) {
    while (~j && board[j].first > Lucky[i]) {
      s += board[j].first;
      c += 1;
      j--;
    }
    ls[i] = s - BigInt(Lucky[i]) * c;
  }
  s = 0;
  c = 0;
  std::sort(board, board + N, cmp);
  for (int i = 0, j = 0; i < tot; i++) {
    while (j < N && board[j].second < Lucky[i]) {
      s += board[j].second;
      c++;
      j++;
    }
    rs[i] = BigInt(Lucky[i]) * c - s;
  }
  int ans = 0;
  for (int i = 0, j = 0; i < tot; i++) {
    while (j < tot && Lucky[j] - Lucky[i] <= minL && ls[i] + rs[j] <= K) j++;
    if (j == i) j++;
    if (Lucky[j - 1] - Lucky[i] <= minL && ls[i] + rs[j - 1] <= K)
      ans = std::max(j - i, ans);
  }
  printf("%d\n", ans);
  return 0;
}
