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 MAX_N = 10 * 100 * 1000 + 10;
const long long INF = (1000000000LL) * (1000000000LL) + 10;
long long N, K;
vector<long long> Lucky;
pair<long long, long long> seg[MAX_N];
long long R[MAX_N], L[MAX_N];
vector<pair<long long, long long> > Temp;
long long Ans[MAX_N];
long long Mul(long long A, long long B) {
  if ((long double)A <= (long double)INF / (long double)B) {
    long long S = A * B;
    if (S < 0 || S >= INF) return INF;
    return S;
  }
  return INF;
}
void FillLucky() {
  Lucky.push_back(4);
  Lucky.push_back(7);
  long long prev = 2;
  for (int i = 0; i < 17; i++) {
    long long SZ = (int)Lucky.size();
    for (int j = SZ - prev; j < SZ; j++)
      Lucky.push_back(Lucky[j] * 10LL + 4LL),
          Lucky.push_back(Lucky[j] * 10LL + 7LL);
    prev *= 2;
  }
  sort(Lucky.begin(), Lucky.end());
}
void FillL() {
  Temp.clear();
  long long C = 0;
  memset(Ans, 0, sizeof(Ans));
  for (int i = 0; i < (int)Lucky.size(); i++)
    Temp.push_back(pair<long long, long long>(Lucky[i], i));
  for (int i = 0; i < N; i++)
    Temp.push_back(pair<long long, long long>(seg[i].second, -1));
  sort(Temp.begin(), Temp.end());
  for (int i = 0; i < (int)Temp.size(); i++) {
    if (i != 0)
      Ans[i] = Ans[i - 1] + Mul((Temp[i].first - Temp[i - 1].first), C),
      Ans[i] = (Ans[i] > INF ? INF : Ans[i]);
    if (Temp[i].second == -1)
      C++;
    else
      L[Temp[i].second] = Ans[i];
  }
}
void FillR() {
  Temp.clear();
  long long C = 0;
  memset(Ans, 0, sizeof(Ans));
  for (int i = 0; i < (int)Lucky.size(); i++)
    Temp.push_back(pair<long long, long long>(Lucky[i], -i));
  for (int i = 0; i < N; i++)
    Temp.push_back(pair<long long, long long>(seg[i].first, 1));
  sort(Temp.begin(), Temp.end());
  reverse(Temp.begin(), Temp.end());
  for (int i = 0; i < (int)Temp.size(); i++) {
    if (i != 0)
      Ans[i] = Ans[i - 1] + Mul((Temp[i - 1].first - Temp[i].first), C),
      Ans[i] = (Ans[i] > INF ? INF : Ans[i]);
    if (Temp[i].second == 1)
      C++;
    else
      R[-Temp[i].second] = Ans[i];
  }
}
int main() {
  ios::sync_with_stdio(false);
  FillLucky();
  cin >> N >> K;
  long long MNSEG = INF;
  for (int i = 0; i < N; i++)
    cin >> seg[i].first >> seg[i].second,
        MNSEG = min(MNSEG, seg[i].second - seg[i].first + 1);
  FillR();
  FillL();
  int i = 0, j = 0;
  int Ans = 0;
  while (j < (int)Lucky.size()) {
    while (i < j && ((L[j] + R[i]) > K || (Lucky[j] - Lucky[i] + 1) > MNSEG))
      i++;
    if ((L[j] + R[i]) <= K && (Lucky[j] - Lucky[i] + 1) <= MNSEG)
      Ans = max(Ans, j - i + 1);
    j++;
  }
  cout << Ans << endl;
  return 0;
}
