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 int maxN = 100 * 1000 + 5;
const long long inf = (1ll << 60);
long long n, k;
long long back[1 << 20], front[1 << 20];
vector<long long> Q;
struct node {
  long long s, e;
  node() {}
  node(long long s, long long e) : s(s), e(e) {}
} a[maxN], b[maxN];
inline bool cmp1(const node &a1, const node &a2) { return a1.s < a2.s; }
inline bool cmp2(const node &a1, const node &a2) { return a1.e < a2.e; }
inline void go(int pos, long long val) {
  if (pos != 0) Q.push_back(val);
  if (pos == 19) return;
  go(pos + 1, val * 10 + 4);
  go(pos + 1, val * 10 + 7);
}
inline void setDyn() {
  int poi = n;
  for (int i = (int)Q.size() - 1; i >= 0; i--)
    if (Q[i] < (1ll << 60)) {
      if (poi != n) {
        if ((Q[i + 1] - Q[i]) > inf / (n - poi)) {
          front[i] = k + 1;
        } else
          front[i] = min(k + 1, (Q[i + 1] - Q[i]) * (n - poi) + front[i + 1]);
      }
      while (poi > 0 && a[poi].s > Q[i]) {
        front[i] += (a[poi].s - Q[i]);
        front[i] = min(front[i], k + 1);
        poi--;
      }
    }
  poi = 1;
  for (int i = 0; i < (int)Q.size(); i++)
    if (Q[i] < (1ll << 60)) {
      if (poi != 1) {
        if ((Q[i] - Q[i - 1]) > inf / (poi - 1))
          back[i] = k + 1;
        else
          back[i] = min(k + 1, (Q[i] - Q[i - 1]) * (poi - 1) + back[i - 1]);
      }
      while (poi <= n && b[poi].e < Q[i]) {
        back[i] += (Q[i] - b[poi].e);
        back[i] = min(k + 1, back[i]);
        poi++;
      }
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  go(0, 0ll);
  sort(Q.begin(), Q.end());
  cin >> n >> k;
  long long minLen = (1ll << 60);
  for (int i = 1; i <= n; i++) {
    cin >> a[i].s >> a[i].e;
    b[i] = a[i];
    minLen = min(minLen, a[i].e - a[i].s + 1);
  }
  sort(a + 1, a + n + 1, cmp1);
  sort(b + 1, b + n + 1, cmp2);
  long long ans = 0;
  setDyn();
  for (int i = 0; i < (int)Q.size(); i++)
    if (Q[i] < (1ll << 60)) {
      long long beg = i, fin = (int)Q.size() - 1;
      while (beg <= fin) {
        long long mid = (beg + fin) / 2;
        if (Q[mid] - Q[i] + 1 > minLen) {
          fin = mid - 1;
          continue;
        }
        long long cost = front[beg] + back[mid];
        if (cost <= k) {
          ans = max(ans, mid - i + 1);
          beg = mid + 1;
        } else
          fin = mid - 1;
      }
    }
  cout << ans << endl;
  return 0;
}
