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;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
long long n, k, p[1000005], cnt, L[1000005], R[1000005];
double sumL, sumR;
struct cmpL {
  bool operator()(long long x, long long y) {
    return L[x] == L[y] ? x < y : L[x] < L[y];
  }
};
struct cmpR {
  bool operator()(long long x, long long y) {
    return R[x] == R[y] ? x < y : R[x] < R[y];
  }
};
multiset<long long, cmpL> s1;
multiset<long long, cmpR> s2;
void dfs(long long x) {
  if (x > 1e18) return;
  if (x != 0) p[++cnt] = x;
  dfs(x * 10 + 4);
  dfs(x * 10 + 7);
}
long long calc(long long ll, long long rr) {
  double right = s1.size(), left = n - s1.size() - s2.size();
  return (sumR - right * ll + left * rr - sumL) <= k;
}
void write(long long x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
signed main() {
  n = read();
  k = read();
  dfs(0);
  sort(p + 1, p + 1 + cnt);
  long long minn = 1e18, ans = 0;
  long long j = 0;
  for (long long i = 1; i <= n; i++) {
    L[i] = read();
    R[i] = read();
    minn = min(minn, R[i] - L[i] + 1);
    sumR += L[i];
    s1.insert(i);
  }
  for (long long i = 1; i <= cnt; i++) {
    while (p[j + 1] - p[i] + 1 <= minn && j < cnt) {
      j++;
      while (s1.size()) {
        long long c = *s1.begin();
        if (L[c] > p[j]) break;
        s1.erase(c);
        sumR -= L[c];
        s2.insert(c);
      }
      while (s2.size()) {
        long long c = *s2.begin();
        if (R[c] >= p[j]) break;
        s2.erase(c);
        sumL += R[c];
      }
      if (calc(p[i], p[j])) {
        ans = max(ans, j - i + 1);
      } else
        break;
      ;
    }
  }
  write(ans);
}
