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:10000000")
const long double LDINF = 9128739847123.00;
const long double eps = 1e-9;
const int inf = 1 << 28;
const long double pi = fabsl(atan2l(0.0, -1.0));
using namespace std;
vector<long long> all;
class Range {
 public:
  long long l, r;
  int i;
  static inline bool cmpl(const Range &a, const Range &b) {
    return a.l < b.l || a.l == b.l && a.r < b.r;
  }
  static inline bool cmpr(const Range &a, const Range &b) {
    return a.r < b.r || a.r == b.r && a.l < b.l;
  }
};
vector<Range> sortedl;
vector<Range> sortedr;
long long K;
int n;
long long maxlen;
void load() {
  cin >> n >> K;
  for (int i = 1; i <= 18; i++) {
    for (int j = 0; j < (1 << i); j++) {
      long long num = 0;
      for (int k = 0; k < i; k++) {
        if (j & (1 << k))
          num = num * 10 + 4;
        else
          num = num * 10 + 7;
      }
      all.push_back(num);
    }
  }
  sort(all.begin(), all.end());
  cerr << all.size();
  maxlen = 1000000000ll * 1000000000ll;
  Range range;
  for (int i = 0; i < n; i++) {
    scanf("%I64d%I64d", &range.l, &range.r);
    range.i = i;
    maxlen = min(maxlen, range.r - range.l);
    sortedl.push_back(range);
    sortedr.push_back(range);
  }
  sort(sortedl.begin(), sortedl.end(), Range ::cmpl);
  sort(sortedr.begin(), sortedr.end(), Range ::cmpr);
}
set<pair<long long, long long> > was;
long long partl[123123];
long long partr[123123];
long long LEFT[525123];
long long right_asdas[525123];
inline long long sum(long long a, long long b) {
  if (a > 1000000000000000000ll || b > 1000000000000000000ll)
    return 1000000000000000001ll;
  if (a + b > 1000000000000000000ll) return 1000000000000000001ll;
  return a + b;
}
inline long long mul(long long a, long long b) {
  if ((double)a * (double)b > 1e18) return 1000000000000000001ll;
  return a * b;
}
void solve() {
  int q = 0;
  for (int i = 0; i < n; i++) {
    if (i)
      partl[i] = sum(partl[i - 1], mul(i, (sortedr[i].r - sortedr[i - 1].r)));
    else
      partl[i] = 0;
    if (i)
      partr[n - i - 1] =
          sum(partr[n - i], mul(i, (sortedl[n - i].l - sortedl[n - i - 1].l)));
    else
      partr[n - i - 1] = 0;
  }
  for (int i = 0; i < all.size(); i++) {
    int l = 0;
    int r = n - 1;
    int mid, res = -1;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (sortedr[mid].r < all[i]) {
        res = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    if (res != -1)
      LEFT[i] = sum(partl[res], mul(((long long)all[i] - sortedr[res].r),
                                    (long long)(res + 1)));
    l = 0;
    r = n - 1;
    res = -1;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (sortedl[mid].l > all[i]) {
        res = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    if (res != -1)
      right_asdas[i] = sum(partr[res], mul(sortedl[res].l - all[i], n - res));
  }
  int res = 0;
  for (int i = 0; i < all.size(); i++) {
    while (q < all.size() && all[q] - all[i] <= maxlen) q++;
    q--;
    if (sum(LEFT[q], right_asdas[i]) <= K && q - i + 1 > res) {
      res = q - i + 1;
    }
  }
  cout << res;
}
int main() {
  load();
  solve();
  return 0;
}
