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;
int n, m;
int k;
bool debug = false;
vector<long long> all;
void init() {
  queue<long long> q;
  q.push(4);
  q.push(7);
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    all.push_back(x);
    if (x >= 1e18) continue;
    q.push(x * 10 + 4);
    q.push(x * 10 + 7);
  }
}
bool jg(long long x) {
  if (x <= 0) return 0;
  while (x > 0) {
    if (x % 10 != 4 && x % 10 != 7) return 0;
    x /= 10;
  }
  return 1;
}
long long l[100005], r[100005], mm;
bool cmp(long long a, long long b) { return a > b; }
int main() {
  init();
  long long n, k;
  double suml = 0;
  cin >> n >> k;
  mm = -1;
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", l + i, r + i);
    long long g = r[i] - l[i];
    suml += l[i];
    if (mm == -1)
      mm = g;
    else
      mm = min(mm, g);
  }
  sort(l, l + n);
  sort(r, r + n);
  int ans = 0;
  double lastsuml = 0;
  for (int allL = 0, allR = 0, p = 0, lastP = 0, q = 0; allR < all.size();) {
    if (allL > allR) {
      allR = allL;
      continue;
    }
    long long g = all[allR] - all[allL];
    if (g > mm) {
      allL++;
      continue;
    }
    double sumMove = lastsuml;
    if (sumMove > k) break;
    while (r[p] < all[allR] && p < n) {
      sumMove += all[allR] - r[p];
      p++;
      if (sumMove > k) {
        break;
      }
    }
    if (lastP != 0) {
      if (1.0 * lastP * (all[allR] - all[allR - 1]) > k) {
        break;
      }
      sumMove += lastP * (all[allR] - all[allR - 1]);
    }
    lastP = p;
    lastsuml = sumMove;
    if (sumMove > k) break;
    long long xx = 0;
    while (l[q] <= all[allL] && q < n) {
      xx += l[q];
      q++;
    }
    suml -= xx;
    if (suml - (all[allL]) * (n - q) > 0)
      sumMove += suml - (all[allL]) * (n - q);
    if (sumMove <= k) {
      ans = max(ans, allR - allL + 1);
      allR++;
    } else {
      allL++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
