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>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
inline void read() {}
template <typename T, typename... Ts>
inline void read(T& A, Ts&... As) {
  T x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  A = x * f, read(As...);
}
inline void write(char a) { putchar(a); }
template <typename T>
inline void write(T a) {
  if (a < 0ll) putchar('-'), a = -a;
  if (a > 9ll) write(a / 10ll);
  putchar(a % 10ll + '0');
}
template <typename T, typename... Ts>
inline void write(T A, Ts... As) {
  write(A), write(As...);
}
const long long N = 600010, inf = 1e18, maxn = 30;
long long n, k, p[N], cnt, len = inf, l[N], r[N], ans, j;
double suml, sumr;
void dfs(long long x) {
  if (x > inf) return;
  p[++cnt] = x, dfs(x * 10 + 4), dfs(x * 10 + 7);
}
struct cmpl {
  bool operator()(long long x, long long y) {
    return l[x] == l[y] ? x < y : l[x] < l[y];
  }
};
struct cmpr {
  bool operator()(long long x, long long y) {
    return r[x] == r[y] ? x < y : r[x] < r[y];
  }
};
multiset<long long, cmpr> s1;
multiset<long long, cmpl> s2;
bool calc(long long L, long long R) {
  double sz2 = s2.size(), sz1 = n - sz2 - s1.size();
  return (sumr - sz2 * L + sz1 * R - suml) <= k;
}
signed main() {
  read(n, k), dfs(4), dfs(7), sort(p + 1, p + cnt + 1);
  for (register long long i = 1; i <= n; ++i)
    read(l[i], r[i]), len = min(len, r[i] - l[i]), s2.insert(i);
  s1.clear(), s2.clear();
  for (register long long i = 1; i <= n; ++i) s2.insert(i), sumr += l[i];
  for (register long long i = 1; i <= cnt; ++i) {
    while (p[j + 1] - p[i] <= len && j < cnt) {
      ++j;
      while (s2.size()) {
        long long k = *s2.begin();
        if (l[k] > p[j]) break;
        s2.erase(k), sumr -= l[k], s1.insert(k);
      }
      while (s1.size()) {
        long long k = *s1.begin();
        if (r[k] >= p[j]) break;
        s1.erase(k), suml += r[k];
      }
      if (calc(p[i], p[j]))
        ans = max(ans, j - i + 1);
      else
        break;
    }
  }
  write(ans);
  return 0;
}
