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;
FILE* g_f_;
int g_s_;
template <class _T>
inline _T sqr(const _T& x) {
  return x * x;
}
template <class _T>
inline string tostr(const _T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-11;
int n, m;
signed long long k;
signed long long a[2000000];
signed long long l[102400];
signed long long r[102400];
int indl[102400];
int indr[102400];
signed long long cl[1024000];
signed long long cr[1024000];
bool cmpl(int p1, int p2) { return l[p1] > l[p2]; }
bool cmpr(int p1, int p2) { return r[p1] < r[p2]; }
int main() {
  cout << setiosflags(ios::fixed) << setprecision(10);
  m = 0;
  for (int i = (1); i <= (int)(18); i++) {
    for (int j = 0; j < (int)(1 << i); j++) {
      signed long long t = 0;
      for (int k = 0; k < (int)(i); k++) {
        t = t * 10 + ((j & (1 << k)) ? 4 : 7);
      }
      a[m++] = t;
    }
  }
  sort(a, a + m);
  (g_s_ = scanf("%d%I64d", &n, &k));
  signed long long mi = 2e18;
  for (int i = 0; i < (int)(n); i++) {
    (g_s_ = scanf("%I64d%I64d", &l[i], &r[i]));
    indl[i] = i;
    indr[i] = i;
    mi = min(mi, r[i] - l[i]);
  }
  sort(indl, indl + n, cmpl);
  sort(indr, indr + n, cmpr);
  memset(cl, 0x3f, sizeof(cl));
  memset(cr, 0x3f, sizeof(cr));
  int ans = 0;
  int ll = 0;
  signed long long ss = 0;
  for (int i = (m)-1; i >= 0; i--) {
    signed long long x = a[i];
    if (ll * 1.0 * (a[i + 1] - x) > 2e18) break;
    ss += ll * (a[i + 1] - x);
    while (ll < n && l[indl[ll]] > x) {
      ss += l[indl[ll]] - x;
      ll++;
      if (ss > k) break;
    }
    if (ss > k) break;
    cl[i] = ss;
  }
  int rr = 0;
  ss = 0;
  for (int i = 0; i < (int)(m); i++) {
    signed long long x = a[i];
    if (rr * 1.0 * (i ? (x - a[i - 1]) : 0) > 2e18) break;
    ss += rr * (i ? (x - a[i - 1]) : 0);
    while (rr < n && r[indr[rr]] < x) {
      ss += x - r[indr[rr]];
      rr++;
      if (ss > k) break;
    }
    if (ss > k) break;
    cr[i] = ss;
  }
  int j = 0;
  for (int i = 0; i < (int)(m); i++) {
    if (j < i) j = i;
    while (j + 1 < m && a[j + 1] - a[i] <= mi && cl[i] + cr[j + 1] <= k) {
      j++;
    }
    if (cl[i] + cr[j] <= k) {
      ans = max(ans, j - i + 1);
    }
  }
  cout << ans << endl;
  return 0;
}
