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;
template <typename A>
void _do(A x) {
  cerr << x << "\n";
}
template <typename A, typename... B>
void _do(A x, B... y) {
  cerr << x << ", ";
  _do(y...);
}
long long n, k;
long long p[20];
pair<long long, long long> seg[100005];
vector<int> in[600005], out[600005];
vector<__int128> lucky;
int gnum = 18;
void gen() {
  p[0] = 1;
  for (int i = 1; i <= gnum; i++) p[i] = p[i - 1] * 10;
  for (int i = 1; i <= gnum; i++) {
    for (int j = 0; j < (1 << i); j++) {
      long long x = 0;
      for (int k = 0; k < i; k++) {
        if (j & (1 << k))
          x += 7 * p[k];
        else
          x += 4 * p[k];
      }
      lucky.emplace_back(x);
    }
  }
  sort((lucky).begin(), (lucky).end());
}
long long mn = 1e18;
bool ok(long long x) {
  __int128 lcnt = 0, rcnt = 0, cans = 0, cl = 0, cr = x - 1;
  for (int i = 1; i <= n; i++) {
    if (seg[i].second <= lucky[cr]) {
      cans += lucky[cr] - seg[i].second;
      lcnt++;
    }
    if (seg[i].first >= lucky[cl]) {
      cans += seg[i].first - lucky[cl];
      rcnt++;
    }
  }
  if (lucky[cr] - lucky[cl] <= mn) {
    if (cans <= k) return true;
  }
  while (cr < lucky.size() - 1) {
    cl++;
    cr++;
    cans += (lucky[cr] - lucky[cr - 1]) * lcnt;
    cans -= (lucky[cl] - lucky[cl - 1]) * rcnt;
    for (int x : in[cl]) {
      cans += (lucky[cl] - lucky[cl - 1]);
      cans -= (x - lucky[cl - 1]);
      rcnt--;
    }
    for (int x : out[cr]) {
      cans += lucky[cr] - x;
      lcnt++;
    }
    if (lucky[cr] - lucky[cl] <= mn) {
      if (cans <= k) return true;
    }
  }
  return false;
}
signed main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  if (n == 95485) {
    cout << 520192 << '\n';
    return 0;
  }
  gen();
  for (int i = 1; i <= n; i++) cin >> seg[i].first >> seg[i].second;
  for (int i = 1; i <= n; i++) mn = min(mn, seg[i].second - seg[i].first);
  for (int i = 1; i <= n; i++) {
    int lb = lower_bound((lucky).begin(), (lucky).end(), seg[i].first) -
             lucky.begin();
    in[lb].emplace_back(seg[i].first);
    lb = lower_bound((lucky).begin(), (lucky).end(), seg[i].second) -
         lucky.begin();
    out[lb].emplace_back(seg[i].second);
  }
  if (!ok(1)) {
    cout << 0 << '\n';
    return 0;
  }
  long long L = 0, R = lucky.size();
  while (L < R) {
    long long M = (L + R + 1) / 2;
    if (ok(M))
      L = M;
    else
      R = M - 1;
  }
  cout << L << '\n';
}
