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 MAXN = 1000 * 100 + 10,
                MAXL = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000;
pair<long long, long long> seg[MAXN], sums[MAXN], sumf[MAXN];
long long n, k, start[MAXN], finish[MAXN], ans, minlen = 1e18 + 10;
vector<long long> lucky;
void read() {
  ios ::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> start[i] >> finish[i];
    minlen = min(minlen, finish[i] - start[i]);
  }
  sort(finish, finish + n);
  sort(start, start + n);
  start[n] = -1;
  finish[n] = 1e18 + 10;
}
void init() {
  sumf[0] = pair<long long, long long>(finish[0], 0);
  sums[n - 1] = pair<long long, long long>(start[n - 1], 0);
  for (int i = 1; i < n; i++) {
    long long R = sumf[i - 1].second - sumf[i - 1].first, Q = sumf[i - 1].first,
              num = i + 1;
    long long tmp = ((R % num) + num) % num;
    Q += ((R - tmp) / num) + (finish[i] / num) +
         (((finish[i] % num) + tmp) / num);
    R = (tmp + (finish[i] % num)) % num;
    sumf[i] = pair<long long, long long>(Q, R);
  }
  for (int i = n - 2; i >= 0; i--) {
    long long R = sums[i + 1].second - sums[i + 1].first, Q = sums[i + 1].first,
              num = n - i;
    long long tmp = ((R % num) + num) % num;
    Q +=
        ((R - tmp) / num) + (start[i] / num) + (((start[i] % num) + tmp) / num);
    R = (tmp + (start[i] % num)) % num;
    sums[i] = pair<long long, long long>(Q, R);
  }
}
void make_lucky() {
  long long beg = 0, end = 2, cnt = 10;
  lucky.push_back(4);
  lucky.push_back(7);
  for (int dig = 1; dig < 18; dig++) {
    for (int i = beg; i < end; i++) lucky.push_back(cnt * 4 + lucky[i]);
    for (int i = beg; i < end; i++) lucky.push_back(cnt * 7 + lucky[i]);
    beg = end;
    end = lucky.size();
    cnt *= 10;
  }
}
bool check(long long beg, long long end) {
  if (minlen < end - beg) return 0;
  int before = lower_bound(finish, finish + n, end) - finish - 1,
      after = upper_bound(start, start + n, beg) - start;
  long long move = 0;
  if (before >= 0 && finish[before] <= end) {
    if ((k + sumf[before].second) / (before + 1) + 1 <
        (end - sumf[before].first))
      return 0;
    else
      move = (end - sumf[before].first) * (before + 1) - sumf[before].second;
  }
  if (start[after] >= beg) {
    if ((k - sums[after].second) / (n - after) + 1 < sums[after].first - beg)
      return 0;
    else
      move += (sums[after].first - beg) * (n - after) + sums[after].second;
  }
  return (k >= move);
}
void solve() {
  long long up = lucky.size() + 10, down = 0, mid;
  while (up - down > 1) {
    bool f = 0;
    mid = (up + down) / 2;
    for (int i = 0; i + mid - 1 < lucky.size(); i++)
      if (check(lucky[i], lucky[i + mid - 1])) {
        f = 1;
        break;
      }
    if (f)
      down = mid;
    else
      up = mid;
  }
  bool f = 0;
  for (int i = 0; i + up - 1 < lucky.size(); i++)
    if (check(lucky[i], lucky[i + up - 1])) f = 1;
  if (f)
    cout << up << endl;
  else
    cout << down << endl;
  return;
}
int main() {
  read();
  init();
  make_lucky();
  solve();
  return 0;
}
