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 comment(linker, "/STACK:134217728")
using namespace std;
vector<long long> lucky;
void luck(long long x) {
  if (x > (long long)1e18) return;
  if (x > 0) lucky.push_back(x);
  luck(x * 10 + 4);
  luck(x * 10 + 7);
}
int n;
long long k;
long long L[1 << 17], R[1 << 17];
long long LD[1 << 19], RD[1 << 19];
double LDD[1 << 19], RDD[1 << 19];
const long long inf = 1LL << 60;
long long MIN = inf;
int main() {
  luck(0);
  sort(lucky.begin(), lucky.end());
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> L[i] >> R[i];
    MIN = min(MIN, R[i] - L[i] + 1);
  }
  sort(L, L + n, greater<long long>());
  sort(R, R + n);
  int p = 0;
  long long d = 0;
  double dd = 0;
  for (int i = 0; i < lucky.size(); ++i) {
    long long prev = i == 0 ? 0 : lucky[i - 1];
    d += (long long)p * (lucky[i] - prev);
    dd += (double)p * (lucky[i] - prev);
    while (p < n && R[p] <= lucky[i]) {
      d += lucky[i] - R[p];
      dd += lucky[i] - R[p];
      ++p;
    }
    if (dd < 4e18)
      LD[i] = d;
    else
      LD[i] = inf;
  }
  p = 0;
  d = 0;
  dd = 0;
  for (int i = (int)lucky.size() - 1; i >= 0; --i) {
    long long prev = i == (int)lucky.size() - 1 ? (1LL << 60) : lucky[i + 1];
    d += (long long)p * (prev - lucky[i]);
    dd += (double)p * (prev - lucky[i]);
    while (p < n && L[p] >= lucky[i]) {
      d += L[p] - lucky[i];
      dd += L[p] - lucky[i];
      ++p;
    }
    if (dd < 4e18)
      RD[i] = d;
    else
      RD[i] = inf;
  }
  int res = 0;
  for (int i = 0; i < lucky.size(); ++i) {
    if (LD[i] + RD[i] <= k) {
      int L = i, R = lucky.size();
      while (R - L > 1) {
        int M = (L + R) / 2;
        if (lucky[M] - lucky[i] + 1 > MIN) {
          R = M;
          continue;
        }
        if (RD[M] == inf || LD[M] == inf) {
          R = M;
          continue;
        }
        if (LD[M] + RD[i] <= k)
          L = M;
        else
          R = M;
      }
      res = max(res, R - i);
    }
  }
  cout << res << endl;
  return 0;
}
