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 oo = 0x3f3f3f3f;
const double eps = 1e-9;
long long loo = 4444444444444444444LL;
long long luck[1000000], L = 0;
long long cost[1000000];
long long cur[1000000];
long long cost1[1000000];
long long cost2[1000000];
int nleft[1000000];
int nright[1000000];
void gen() {
  luck[0] = 0;
  int i = 0;
  L = 1;
  while (i < L) {
    if (luck[i] > 100000000000000000LL) break;
    luck[L++] = luck[i] * 10 + 4;
    luck[L++] = luck[i++] * 10 + 7;
  }
  luck[0] = -4444444444444444444LL;
  luck[L] = 4444444444444444444LL;
}
int N;
long long MSTEP;
long long l[100100], r[100100];
int nextleft[100100];
int nextright[100100];
void genLR() {
  for (int i = (0); i < (N); i++) {
    int lo = 0, hi = L;
    while (lo != hi) {
      int mid = lo + (hi - lo + 1) / 2;
      if (luck[mid] > l[i])
        hi = mid - 1;
      else
        lo = mid;
    }
    nextleft[i] = lo;
    lo = 0, hi = L;
    while (lo != hi) {
      int mid = lo + (hi - lo) / 2;
      if (luck[mid] < r[i])
        lo = mid + 1;
      else
        hi = mid;
    }
    nextright[i] = lo;
  }
}
long long minlen;
long long add(long long v, long long mul1, long long mul2) {
  long long tmp = mul1 * mul2;
  if (mul1 != 0)
    if (mul2 != tmp / mul1) return loo;
  tmp = min(loo, tmp);
  tmp += v;
  return min(loo, tmp);
}
void genCost() {
  for (int i = (0); i < (L + 1); i++) cur[i] = 0;
  for (int i = (0); i < (L + 1); i++) nleft[i] = 0;
  for (int i = (0); i < (N); i++) {
    int tt = nextleft[i];
    nleft[tt]++;
    cur[tt] = add(cur[tt], l[i] - luck[tt], 1);
  }
  int act = 0;
  for (int i = int(L) - 1; i >= (0); i--) {
    cur[i] = add(cur[i], cur[i + 1], 1);
    cur[i] = add(cur[i], act, luck[i + 1] - luck[i]);
    act += nleft[i];
    cost1[i] = cur[i];
  }
  for (int i = (0); i < (L + 1); i++) cur[i] = 0;
  for (int i = (0); i < (L + 1); i++) nright[i] = 0;
  for (int i = (0); i < (N); i++) {
    int tt = nextright[i];
    nright[tt]++;
    cur[tt] = add(cur[tt], luck[tt] - r[i], 1);
  }
  act = 0;
  for (int i = (1); i < (L); i++) {
    cur[i] = add(cur[i], cur[i - 1], 1);
    cur[i] = add(cur[i], act, luck[i] - luck[i - 1]);
    act += nright[i];
    cost2[i] = cur[i];
  }
}
bool check(int k) {
  if (k == 0) return 1;
  for (int i = (1); i < (L - k + 1); i++) {
    if (cost1[i] + cost2[i + k - 1] <= MSTEP &&
        luck[i + k - 1] - luck[i] <= minlen)
      return 1;
  }
  return 0;
}
int main() {
  gen();
  cin >> N >> MSTEP;
  for (int i = (0); i < (N); i++) cin >> l[i] >> r[i];
  genLR();
  genCost();
  minlen = r[0] - l[0];
  for (int i = (0); i < (N); i++) minlen = min(minlen, r[i] - l[i]);
  int lo = 0, hi = L;
  while (lo != hi) {
    int mid = lo + (hi - lo + 1) / 2;
    if (check(mid))
      lo = mid;
    else
      hi = mid - 1;
  }
  cout << lo << endl;
  return 0;
}
