#include <bits/stdc++.h>
using namespace std;
int n;
unsigned long long k;
unsigned long long minlen = 1e18 + 0.5;
unsigned long long lefts[110000];
unsigned long long rights[110000];
unsigned long long sum_lefts[110000];
unsigned long long sum_rights[110000];
vector<unsigned long long> luckies;
void gen_lucky(int rem, unsigned long long cur) {
  if (cur) luckies.push_back(cur);
  if (rem == 0) return;
  gen_lucky(rem - 1, cur * 10 + 4);
  gen_lucky(rem - 1, cur * 10 + 7);
}
unsigned long long calc(unsigned long long st, unsigned long long ed) {
  int idxL = upper_bound(lefts, lefts + n, st) - lefts;
  int idxR = upper_bound(rights, rights + n, ed) - rights;
  unsigned long long sL = sum_lefts[n] - sum_lefts[idxL];
  unsigned long long sR = sum_rights[idxR];
  return (sL - st * (n - idxL)) + (ed * (idxR)-sR);
}
int main() {
  scanf("%d %llu", &n, &k);
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    scanf("%llu %llu", &lefts[i], &rights[i]);
    minlen = min(minlen, rights[i] - lefts[i]);
  }
  gen_lucky(18, 0);
  sort(luckies.begin(), luckies.end());
  sort(lefts, lefts + n);
  sort(rights, rights + n);
  for (int(i) = 0; (i) < (int)(n); (i)++) {
    sum_lefts[i + 1] = sum_lefts[i] + lefts[i];
    sum_rights[i + 1] = sum_rights[i] + rights[i];
  }
  unsigned long long stL = 0, edL = 1e18 + 0.5;
  while (stL < edL) {
    unsigned long long m = (stL + edL) / 2;
    unsigned long long cursum = 0;
    bool ok = true;
    for (int(i) = 0; (i) < (int)(n); (i)++) {
      if (m < lefts[i]) cursum += lefts[i] - m;
      if (cursum > k) ok = false;
    }
    if (ok)
      edL = m;
    else
      stL = m + 1;
  }
  unsigned long long stR = 0, edR = 1e18 + 0.5;
  while (stR < edR) {
    unsigned long long m = (stR + edR + 1) / 2;
    unsigned long long cursum = 0;
    bool ok = true;
    for (int(i) = 0; (i) < (int)(n); (i)++) {
      if (m > rights[i]) cursum += m - rights[i];
      if (cursum > k) ok = false;
    }
    if (ok)
      stR = m;
    else
      edR = m - 1;
  }
  int best = 0;
  int right = -1;
  for (int(left) = 0; (left) < (int)(luckies.size()); (left)++) {
    if (luckies[left] < stL) continue;
    right = max(right, left - 1);
    while (right + 1 < (int)luckies.size()) {
      if (luckies[right + 1] > stR) break;
      if (luckies[right + 1] - luckies[left] > minlen) break;
      unsigned long long tot = calc(luckies[left], luckies[right + 1]);
      if (tot > k) break;
      right++;
    }
    best = max(best, right - left + 1);
  }
  printf("%d\n", best);
}
