#include <bits/stdc++.h>
using namespace std;
const long long N = (1 << 19) + 12, INF = 1e18, LOG10 = 26, NF = 2e18;
long long n, k, mn = INF, real_ans;
long long tav[N];
long long l[N], r[N];
vector<long long> lucky;
long long R[N], L[N];
void pre();
void init();
void solve();
void out();
bool is_bad(long long, long long);
long long sum(long long A, long long B) {
  if (A == NF || B == NF) return NF;
  A += B;
  if (A > INF) A = NF;
  return A;
}
long long mul(long long a, long long b) {
  if (a == 0 || b == 0) return 0;
  if (a == NF || b == NF) return NF;
  if (log(a) + log(b) > log(INF)) return NF;
  return (a * b);
}
int32_t main() {
  pre();
  init();
  solve();
  out();
  return 0;
}
void pre() {
  tav[0] = 1;
  for (long long i = 1; i < 19; i++) tav[i] = tav[i - 1] * 10;
  for (n = 0; n < 19; n++)
    for (long long msk = 0; msk < (1 << n); msk++) {
      long long now = 0;
      for (long long i = 0; i < n; i++) {
        if (msk & (1 << i))
          now += 7 * tav[i];
        else
          now += 4 * tav[i];
      }
      if (now <= INF && now != 0) {
        lucky.push_back(now);
      }
    }
  sort(lucky.begin(), lucky.end());
  return;
}
void init() {
  cin >> n >> k;
  for (long long i = 0; i < n; i++) {
    cin >> l[i] >> r[i];
    mn = min(r[i] - l[i] + 1, mn);
  }
  sort(l, l + n);
  sort(r, r + n);
  return;
}
void solve() {
  long long id = -1;
  long long now = 0;
  long long ls = 0;
  long long cnt = 0;
  for (long long i = 0; i < lucky.size(); i++) {
    now = sum(now, mul(lucky[i] - ls, cnt));
    while (id + 1 < n && r[id + 1] < lucky[i]) {
      id++;
      now = sum(now, abs(r[id] - lucky[i]));
      cnt++;
    }
    ls = lucky[i];
    R[i] = now;
  }
  id = n;
  now = 0;
  ls = 0;
  cnt = 0;
  for (long long i = lucky.size() - 1; i >= 0; i--) {
    now = sum(now, mul(ls - lucky[i], cnt));
    while (id > 0 && l[id - 1] > lucky[i]) {
      id--;
      now = sum(now, l[id] - lucky[i]);
      cnt++;
    }
    ls = lucky[i];
    L[i] = now;
  }
  long long st = 0;
  for (long long en = 0; en < lucky.size(); en++) {
    if (is_bad(en, en)) continue;
    real_ans = max(real_ans, 1ll);
    long long low = en;
    long long high = lucky.size();
    while (high - low > 1) {
      long long mid = (low + high) >> 1;
      if (is_bad(en, mid))
        high = mid;
      else
        low = mid;
    }
    real_ans = max(real_ans, low - en + 1);
  }
  return;
}
void out() {
  cout << real_ans;
  return;
}
bool is_bad(long long st, long long en) {
  long long len = lucky[en] - lucky[st] + 1;
  if (len > mn) return 1;
  long long val = sum(L[en], R[st]);
  return (val > k);
}
