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>
const int inf = (1ll << 30) - 1;
const int maxn = (int)1e5 + 10;
const int mod = (int)1e9 + 7;
using namespace std;
int n;
long long k;
pair<long long, long long> a[100100];
long long b[100100];
long long lim = 2 * (long long)(1e18) + 1;
long long M = lim;
vector<long long> d, c;
long long L[2000100], R[2000100];
void precalcleft() {
  for (int i = 0; i < n; i++) {
    b[i] = a[i].first;
  }
  sort(b, b + n);
  int r = n - 1;
  for (int i = 0; i < c.size(); i++) {
    L[i] = k + 1;
  }
  long long second = 0;
  for (int i = (int)c.size() - 1; i >= 0 && second <= k; i--) {
    if (i + 1 < c.size() && n != r + 1) {
      long long a = n - r - 1;
      long long b = c[i + 1] - c[i];
      if ((k + 1) / b >= a) {
        second += a * b;
      } else
        second = k + 1;
    }
    while (second <= k && r >= 0 && c[i] < b[r]) {
      second += b[r] - c[i];
      r--;
    }
    L[i] = min(second, k + 1);
  }
}
void precalcright() {
  for (int i = 0; i < n; i++) {
    b[i] = a[i].second;
  }
  sort(b, b + n);
  int r = 0;
  for (int i = 0; i < c.size(); i++) {
    R[i] = k + 1;
  }
  long long second = 0;
  for (int i = 0; i < c.size(); i++) {
    if (i > 0 && r > 0) {
      long long a = r;
      long long b = c[i] - c[i - 1];
      if ((k + 1) / b >= a) {
        second += a * b;
      } else
        second = k + 1;
    }
    while (second <= k && r < n && c[i] > b[r]) {
      second += c[i] - b[r];
      r++;
    }
    R[i] = min(second, k + 1);
  }
}
bool can(int l) {
  for (int i = l - 1; i < c.size(); i++) {
    if (c[i] - c[i - l + 1] > M) continue;
    if (L[i - l + 1] + R[i] <= k) {
      return 1;
    }
  }
  return 0;
}
void solve() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first >> a[i].second;
    M = min(a[i].second - a[i].first, M);
  }
  d.push_back(4);
  d.push_back(7);
  while (d.size() > 0) {
    vector<long long> dd;
    for (int i = 0; i < d.size(); i++) {
      c.push_back(d[i]);
      if ((lim - 4) / 10 >= d[i] && d[i] * 10 + 4 <= lim)
        dd.push_back(d[i] * 10 + 4);
      if ((lim - 7) / 10 >= d[i] && d[i] * 10 + 7 <= lim)
        dd.push_back(d[i] * 10 + 7);
    }
    d = dd;
  }
  precalcleft();
  precalcright();
  int l = 1, r = c.size();
  int res = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (can(mid)) {
      res = mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  cout << res << "\n";
}
int main() {
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
