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>
using namespace std;
const double eps = 1e-8;
vector<long long> lucky;
void gao(int dep, long long now) {
  if (now) lucky.push_back(now);
  if (dep >= 18) return;
  gao(dep + 1, now * 10 + 4);
  gao(dep + 1, now * 10 + 7);
}
int n;
unsigned long long mini;
unsigned long long L[100007], R[100007], k;
struct BigInteger {
  static const int LEN = 2;
  static const long long MOD;
  long long a[LEN];
  explicit BigInteger(long long x) {
    fill(a + 1, a + LEN, 0LL);
    a[0] = x;
    for (int i = 0; a[i] >= MOD; ++i) {
      a[i + 1] += a[i] / MOD;
      a[i] %= MOD;
    }
  }
  BigInteger(const BigInteger& o) { copy(o.a, o.a + LEN, a); }
  void operator+=(const BigInteger& o) {
    for (int i = 0; i < LEN; ++i) {
      a[i] += o.a[i];
      while (a[i] >= MOD) {
        ++a[i + 1];
        a[i] -= MOD;
      }
    }
  }
  void operator-=(const BigInteger& o) {
    for (int i = 0; i < LEN; ++i) {
      a[i] -= o.a[i];
      while (a[i] < 0) {
        --a[i + 1];
        a[i] += MOD;
      }
    }
  }
  bool operator<=(const BigInteger& o) {
    for (int i = LEN - 1; i >= 0; --i) {
      if (a[i] != o.a[i]) {
        return a[i] < o.a[i];
      }
    }
    return true;
  }
  void dump() const {
    for (int i = LEN - 1; i >= 0; --i) {
      printf("%08lld,", a[i]);
    }
    puts("");
  }
};
bool gao(int len) {
  long long last = lucky[0], last2 = lucky[len - 1], now = 0, p1 = 0, p2 = 0;
  BigInteger cnt(0), ff(k);
  while (p1 < n && L[p1] <= lucky[0]) ++p1;
  for (int i = p1; i < n; ++i) cnt += BigInteger(L[i] - lucky[0]);
  while (p2 < n && R[p2] <= lucky[len - 1]) ++p2;
  for (int i = 0; i < p2; i++) cnt += BigInteger(lucky[len - 1] - R[i]);
  for (int i = 0; i + len - 1 < lucky.size(); ++i) {
    long long p3 = p2;
    while (p1 < n && L[p1] <= lucky[i]) cnt -= BigInteger(L[p1] - last), ++p1;
    while (p2 < n && R[p2] <= lucky[i + len - 1])
      cnt += BigInteger(lucky[i + len - 1] - R[p2]), ++p2;
    cnt -= BigInteger((lucky[i] - last) * (n - (long long)p1));
    cnt += BigInteger((lucky[i + len - 1] - last2) * ((long long)p3));
    last = lucky[i], last2 = lucky[i + len - 1];
    if (lucky[i + len - 1] - lucky[i] <= mini && cnt <= ff) return true;
    if (p1 >= n && !(cnt <= ff)) return false;
  }
  return false;
}
const long long BigInteger::MOD = 100000000000000000LL;
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> L[i] >> R[i];
  mini = R[0] - L[0];
  for (int i = 0; i < n; i++) mini = min(mini, R[i] - L[i]);
  sort(L, L + n);
  sort(R, R + n);
  gao(0, 0);
  sort(lucky.begin(), lucky.end());
  int l = 0, r = lucky.size();
  while (l < r) {
    int mid = ((l + r) >> 1) + 1;
    if (gao(mid))
      l = mid;
    else
      r = mid - 1;
  }
  cout << l << endl;
  return 0;
}
