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;
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
inline void read(long long *a, long long n) {
  for (long long i = 0; i < n; i++) a[i] = in();
}
template <class blank>
inline void out(blank x) {
  cout << x << "\n";
  exit(0);
}
const long long maxn = 1e5 + 10;
const long long maxm = 1e6 + 10;
const long long maxlg = 21;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e18 + 10;
const long long SQ = 317 + 5;
long long n, k;
pair<long long, long long> seg[maxn];
long long r[maxn], l[maxn];
vector<long long> lucky;
inline void build(long long num) {
  if (num <= 1e18) {
    if (num) lucky.push_back(num);
    if (num <= 1e17) build(num * 10 + 7), build(num * 10 + 4);
  }
}
long long suf[maxn], pref[maxn];
inline long long addRight(long long num) {
  long long ret = 0;
  long long upp = upper_bound(r, r + n, num) - r;
  long long cnt = upp;
  ret += cnt * num - (upp ? pref[upp - 1] : 0);
  return ret;
}
inline long long addLeft(long long num) {
  long long ret = 0;
  long long upp = upper_bound(l, l + n, num) - l;
  long long cnt = n - upp;
  ret += -cnt * num + suf[upp];
  return ret;
}
bool ovflow[maxn];
inline bool ok(long long num) {
  long long upp = upper_bound(r, r + n, num) - r;
  long long cnt = upp;
  if ((double)2e18 / cnt < num) return false;
  upp = upper_bound(l, l + n, num) - l;
  if (ovflow[upp]) return false;
  return true;
}
long long res;
int32_t main() {
  n = in(), k = lin();
  long long mini = INF;
  for (long long i = 0; i < n; i++) {
    seg[i] = {lin(), lin()};
    l[i] = seg[i].first, r[i] = seg[i].second;
    mini = min(mini, seg[i].second - seg[i].first + 1);
  }
  sort(l, l + n);
  sort(r, r + n);
  for (long long i = 0; i < n; i++) pref[i] = (i ? pref[i - 1] : 0) + r[i];
  for (long long i = n - 1; i >= 0; i--) {
    suf[i] = suf[i + 1] + l[i];
    if (2e18 - l[i] < suf[i + 1]) ovflow[i] = true;
    ovflow[i] |= ovflow[i + 1];
  }
  build(0);
  sort(lucky.begin(), lucky.end());
  long long l = 0;
  long long need = 0;
  for (long long pt = 0; pt < lucky.size(); pt++) {
    if (!ok(lucky[pt])) {
      need = 0;
      l = pt + 1;
      continue;
    }
    if (l < pt) need -= addRight(lucky[pt - 1]);
    need += addRight(lucky[pt]) + (pt == l ? addLeft(lucky[pt]) : 0);
    while (need > k || (pt >= l && lucky[pt] - lucky[l] + 1 > mini)) {
      need -= addLeft(lucky[l]);
      if (l + 1 <= pt) {
        need += addLeft(lucky[l + 1]);
      } else
        need -= addRight(lucky[l]);
      l++;
    }
    res = max(res, pt - l + 1);
  }
  cout << res << "\n";
}
