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;
ifstream fin("in.in");
ofstream fout("out.out");
const int N = 1e5 + 10, M = 1e6 + 10;
long long n, k, res, minLen(1e18);
long long cL[M + N], cR[M + N], l[M], r[M];
vector<long long> lucky;
vector<pair<long long, int> > a;
void make(int cnt, long long x = 0) {
  if (!cnt) {
    a.push_back(make_pair(x, 0));
    lucky.push_back(x);
    return;
  }
  make(cnt - 1, 10 * x + 4);
  make(cnt - 1, 10 * x + 7);
}
inline long long add(long long s, long long x) {
  if (s > k - x) return k + 1;
  return s + x;
}
inline long long mul(long long x, long long y) {
  if (y && x > k / y) return k + 1;
  return x * y;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i <= 18; i++) make(i);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    long long l, r;
    cin >> l >> r;
    minLen = min(minLen, r - l);
    a.push_back(make_pair(l, +1));
    a.push_back(make_pair(r, -1));
  }
  n = a.size();
  sort(a.begin(), a.end());
  sort(lucky.begin(), lucky.end());
  long long nL = 0;
  for (int i = 1; i < n; i++) {
    cL[i] = add(cL[i - 1], mul(nL, a[i].first - a[i - 1].first));
    nL += a[i].second == -1;
  }
  long long nR = 0;
  for (int i = n - 2; i >= 0; i--) {
    cR[i] = add(cR[i + 1], mul(nR, a[i + 1].first - a[i].first));
    nR += a[i].second == +1;
  }
  bool imp = true;
  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (!a[i].second) {
      if (cR[i] + cL[i] <= k) imp = false;
      r[cnt] = cR[i], l[cnt] = cL[i];
      cnt++;
    }
  if (imp) return (cout << 0), 0;
  int j = 0;
  n = cnt;
  for (int i = 0; i < n; i++) {
    if (l[i] + r[i] > k) continue;
    j = max(i, j);
    while (j < n && lucky[j] - lucky[i] <= minLen && r[i] + l[j] <= k) j++;
    res = (((res) > (j - i)) ? ((res)) : ((j - i)));
    j--;
  }
  cout << res << endl;
  return 0;
}
