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;
const long long maxv = 1e18;
const int maxn = 6 * 1000 * 100, maxs = 1000 * 100 + 7;
int n;
vector<long long> luck;
queue<long long> q;
long long k, mov[2][maxn], l[maxn], r[maxn], mnLen = maxv;
;
int p[maxn];
void make_luck() {
  luck.push_back(4 * 1LL);
  luck.push_back(7 * 1LL);
  q.push(4);
  q.push(7);
  while (1) {
    long long id = q.front();
    if (id * 10 > maxv) break;
    luck.push_back(id * 10 + 4 * 1LL);
    q.push(id * 10 + 4 * 1LL);
    luck.push_back(id * 10 + 7 * 1LL);
    q.push(id * 10 + 7 * 1LL);
    q.pop();
  }
}
bool cmpL(int i, int j) { return l[i] > l[j]; }
bool cmpR(int i, int j) { return r[i] < r[j]; }
long long sum(long long x, long long y) { return x > k - y ? k + 1 : x + y; }
long long mul(long long x, long long y) {
  return (y && x > k / y) ? k + 1 : x * y;
}
int bin(int r1, int r2, int l) {
  while (r2 - r1 > 1) {
    int mid = (r1 + r2) / 2;
    long long need = mov[1][l] + mov[0][mid];
    if (need <= k && luck[mid] - luck[l] <= mnLen)
      r1 = mid;
    else
      r2 = mid;
  }
  return r2;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    mnLen = min(mnLen, r[i] - l[i]);
    p[i] = i;
  }
  make_luck();
  sort(p, p + n, cmpR);
  int j = 0;
  for (int i = 0; i < luck.size(); i++) {
    long long x = luck[i];
    if (i) mov[0][i] = sum(mov[0][i - 1], mul(x - luck[i - 1], j));
    while (j < n && r[p[j]] < x) mov[0][i] = sum(mov[0][i], x - r[p[j++]]);
  }
  sort(p, p + n, cmpL);
  j = 0;
  for (int i = luck.size() - 1; i >= 0; i--) {
    long long x = luck[i];
    if (i + 1 < luck.size())
      mov[1][i] = sum(mov[1][i + 1], mul(luck[i + 1] - x, j));
    while (j < n && l[p[j]] > x) mov[1][i] = sum(mov[1][i], l[p[j++]] - x);
  }
  int ans = 0;
  for (int l = 0; l < luck.size(); l++) {
    if (mov[1][l] + mov[0][l] > k) continue;
    ans = max(ans, bin(l, luck.size(), l) - l);
  }
  cout << ans << endl;
}
