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:20000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const int inf = (int)2e9, mod = (int)1e9 + 7;
const long long linf = (long long)2e18;
const int maxn = (int)1e5 + 666, maxn2 = (int)1e6 + 666;
long long l[maxn], r[maxn];
long double pref1[maxn], pref2[maxn];
long double suff1[maxn], rsuff[maxn];
long long mn = linf;
int n;
long long k;
long double N;
bool check(long double L, long double R) {
  if (R - L + 1 > mn) {
    return false;
  }
  long double ID1 = lower_bound(l + 1, l + n + 1, L + 1) - l;
  int IDD1 = lower_bound(l + 1, l + n + 1, L + 1) - l;
  long double F = pref1[n] - pref1[IDD1 - 1];
  long double G = (N - ID1 + 1) * L;
  if (F - G > k) return false;
  long double ID2 = lower_bound(r + 1, r + n + 1, R) - r;
  --ID2;
  int IDD2 = lower_bound(r + 1, r + n + 1, R) - r;
  --IDD2;
  long double FF = pref2[IDD2];
  long double GG = ID2 * L;
  if (GG - FF > k) return false;
  long double zero = 0;
  if (max(zero, F - G) + max(zero, GG - FF) > k) return false;
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  N = n;
  for (int i = 1; i <= n; ++i) {
    cin >> l[i] >> r[i];
    mn = min(r[i] - l[i] + 1, mn);
  }
  sort(l + 1, l + n + 1);
  sort(r + 1, r + n + 1);
  for (int i = 1; i <= n; ++i) pref1[i] = pref1[i - 1] + l[i];
  for (int i = 1; i <= n; ++i) pref2[i] = pref2[i - 1] + r[i];
  vector<long double> v;
  for (int len = 1; len <= 18; ++len) {
    for (int mask = 0; mask < (1 << len); ++mask) {
      long double num = 0;
      for (int i = 0; i < len; ++i) {
        num *= 10;
        if (!(mask & (1 << i))) {
          num += 4;
        } else {
          num += 7;
        }
      }
      v.push_back(num);
    }
  }
  sort(v.begin(), v.end());
  int R = 0, ans = 0;
  for (int i = 0; i < ((int)v.size()); ++i) {
    R = max(R, i);
    while (R < ((int)v.size()) && check(v[i], v[R])) {
      ++R;
    }
    --R;
    ans = max(ans, R - i + 1);
  }
  cout << ans;
  return 0;
}
