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:300000000")
using namespace std;
const double pi = 3.1415926535897932384626433832795;
template <class T>
T abs(T &a) {
  return a >= 0 ? a : -a;
};
template <class T>
T sqr(T &x) {
  return x * x;
}
int a, b;
vector<long long> h;
void rec(long long cur) {
  if (cur > 1000000000000000000LL) return;
  if (cur) h.push_back(cur);
  rec(cur * 10 + 4);
  rec(cur * 10 + 7);
}
struct segment {
  long long l, r;
};
vector<segment> v;
vector<long long> toL, toR;
int n;
long long k;
bool cmpL(segment &a, segment &b) { return a.l < b.l; }
bool cmpR(segment &a, segment &b) { return a.r < b.r; }
const long long inf = 1000000000000000000LL + 10;
int main() {
  rec(0);
  sort((h).begin(), (h).end());
  cin >> n >> k;
  v.resize(n);
  toL.resize(((int)(h).size()));
  toR.resize(((int)(h).size()));
  for (int i = 0; i < (n); i++) cin >> v[i].l >> v[i].r;
  long long minLen = 1000000000000000000LL + 10;
  for (int i = 0; i < (n); i++) minLen = min(minLen, v[i].r - v[i].l);
  sort((v).begin(), (v).end(), cmpR);
  int segCnt = 0;
  long long curSum = 0;
  double curSumAppr = 0;
  for (int i = 0; i < (((int)(h).size())); i++) {
    while (segCnt < n && v[segCnt].r <= h[i]) {
      if (segCnt > 0) {
        if (curSum + (double)segCnt * (v[segCnt].r - v[segCnt - 1].r) > inf)
          curSum = inf;
        else
          curSum += segCnt * (v[segCnt].r - v[segCnt - 1].r);
      }
      segCnt++;
    }
    long long lastX = 0;
    if (segCnt > 0) lastX = v[segCnt - 1].r;
    if (i > 0) lastX = max(lastX, h[i - 1]);
    if (curSum + (double)segCnt * (h[i] - lastX) > inf)
      curSum = inf;
    else
      curSum += segCnt * (h[i] - lastX);
    toR[i] = curSum;
  }
  sort((v).begin(), (v).end(), cmpL);
  segCnt = 0;
  curSum = 0;
  for (int i = ((int)(h).size()) - 1; i >= 0; i--) {
    while (segCnt < n && v[n - segCnt - 1].l >= h[i]) {
      if (segCnt > 0) {
        if (curSum + (double)segCnt * (v[n - segCnt].l - v[n - segCnt - 1].l) >
            inf)
          curSum = inf;
        else
          curSum += segCnt * (v[n - segCnt].l - v[n - segCnt - 1].l);
      }
      segCnt++;
    }
    long long lastX = inf;
    if (segCnt > 0) lastX = v[n - segCnt].l;
    if (i < ((int)(h).size()) - 1) lastX = min(lastX, h[i + 1]);
    if (curSum + (double)segCnt * (lastX - h[i]) > inf)
      curSum = inf;
    else
      curSum += segCnt * (lastX - h[i]);
    toL[i] = curSum;
  }
  int ans = 0;
  int r = -1;
  for (int l = 0; l < (((int)(h).size())); l++) {
    r = max(r, l - 1);
    while (r < ((int)(h).size()) - 1 && h[r + 1] - h[l] <= minLen &&
           toL[l] + toR[r + 1] <= k)
      r++;
    ans = max(ans, r - l + 1);
  }
  cout << ans;
}
