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 = 6e5 + 10;
const long long inf = 1e18 + 500000;
long long K;
long long mn;
long long ans;
long long n, k;
long long l[maxn];
long long r[maxn];
long long L[maxn];
long long R[maxn];
long long O[maxn];
vector<long long> luckies;
void in();
void solve();
void make_luckies();
bool cmpR(long long, long long);
bool cmpL(long long, long long);
long long find(long long, long long);
void make_L();
void make_R();
void out();
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  in();
  solve();
  out();
}
void in() {
  cin >> n >> k;
  K = k;
  for (long long i = 0; i != n; i++) {
    cin >> l[i] >> r[i];
  }
}
void solve() {
  mn = inf;
  for (long long i = 0; i < n; i++) mn = min(mn, r[i] - l[i]);
  make_luckies();
  make_R();
  make_L();
  for (long long i = 0; i < luckies.size(); i++)
    if (L[i] <= k) ans = max(ans, find(i, k - L[i]));
}
long long find(long long l, long long k) {
  if (R[l] > k) return 0;
  long long ret = l;
  long long s = l;
  long long e = luckies.size();
  while (e - s != 1) {
    long long mid = (s + e) >> 1;
    if (luckies[mid] - luckies[l] > mn)
      e = mid;
    else
      s = mid;
  }
  long long r = e;
  while (r - l != 1) {
    long long mid = (l + r) >> 1;
    if (R[mid] <= k)
      l = mid;
    else
      r = mid;
  }
  ret = r - ret;
  return ret;
}
void make_R() {
  for (long long i = 0; i < n; i++) O[i] = i;
  sort(O, O + n, cmpR);
  long long cnt = 0;
  long long val = 0;
  long long now = 0;
  for (long long i = 0; i < luckies.size(); i++) {
    if (i != 0 && cnt) {
      if (inf / cnt <= (luckies[i] - luckies[i - 1]) - 1) {
        val = inf;
      } else {
        val += cnt * (luckies[i] - luckies[i - 1]);
        if (val < 0) val = inf;
        val = min(val, inf);
      }
    }
    while (now < n && r[O[now]] <= luckies[i]) {
      val += luckies[i] - r[O[now++]];
      val = min(val, inf);
      cnt++;
    }
    val = min(val, inf);
    R[i] = val;
  }
}
bool cmpR(long long i, long long j) { return r[i] < r[j]; }
void make_L() {
  sort(O, O + n, cmpL);
  long long cnt = 0;
  long long val = 0;
  long long now = 0;
  for (long long i = luckies.size() - 1; i >= 0; i--) {
    if (i != luckies.size() - 1 && cnt) {
      if (inf / cnt <= (luckies[i + 1] - luckies[i]) - 1) {
        val = inf;
      } else {
        val += cnt * (luckies[i + 1] - luckies[i]);
        if (val < 0) val = inf;
        val = min(val, inf);
      }
    }
    while (now < n && l[O[now]] >= luckies[i]) {
      val += l[O[now++]] - luckies[i];
      val = min(val, inf);
      cnt++;
    }
    val = min(val, inf);
    L[i] = val;
  }
}
bool cmpL(long long i, long long j) { return l[i] > l[j]; }
void make_luckies() {
  for (long long i = 1; i <= 18; i++) {
    for (long long j = 0; j < (1 << i); j++) {
      long long num = 0;
      for (long long k = i - 1; k >= 0; k--) {
        num = num * 10 + 4;
        if ((1 << k) & j) num += 3;
      }
      luckies.push_back(num);
    }
  }
}
void out() { cout << ans; }
