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;
using namespace std;
const int bignumlen = 5;
const int Blen = 8;
const long long base = 100000000;
struct bignum {
  int len;
  long long data[bignumlen];
  long long &operator[](int x) { return (data[x]); }
  const long long &operator[](int x) const { return (data[x]); }
  bignum() {
    memset(data, 0, sizeof(data));
    len = 0;
  }
  void clear() {
    for (int i = len; i >= 1; --i) data[i] = 0;
    len = 0;
  }
  int check(const bignum &a, const bignum &b) {
    if (a.len > b.len) return (0);
    if (b.len > a.len) return (1);
    for (int i = a.len; i >= 1; --i) {
      if (a.data[i] < b.data[i]) return (1);
      if (b.data[i] < a.data[i]) return (0);
    }
    return 2;
  }
  bool operator<(const bignum &b) { return (check(*this, b) == 1); }
  bool operator>(const bignum &b) { return (check(*this, b) == 0); }
  bool operator<=(const bignum &b) { return (check(*this, b) >= 1); }
  bool operator>=(const bignum &b) { return (check(*this, b) % 2 == 0); }
  bool operator!=(const bignum &b) { return (check(*this, b) != 2); }
  bool operator==(const bignum &b) { return (check(*this, b) == 2); }
  bignum operator=(const bignum &x) {
    for (int i = x.len + 1; i <= len; ++i) data[i] = 0;
    for (int i = 1; i <= x.len; ++i) data[i] = x.data[i];
    len = x.len;
    return *this;
  }
  bignum operator=(long long x) {
    for (int i = len; i >= 0; --i) data[i] = 0;
    len = 0;
    while (x) {
      data[++len] = x % base;
      x /= base;
    }
    return *this;
  }
  bignum(long long x) {
    memset(data, 0, sizeof(data));
    len = 0;
    (*this) = x;
  }
  bignum operator*(const bignum &b) {
    int i, j;
    bignum tmp;
    for (i = 1; i <= len; ++i)
      if (data[i] != 0)
        for (j = 1; j <= b.len; ++j)
          if (b.data[j] != 0) {
            tmp.data[i + j - 1] += data[i] * b.data[j];
            tmp.data[i + j] += tmp.data[i + j - 1] / base;
            tmp.data[i + j - 1] %= base;
          }
    tmp.len = len + b.len - 1;
    while (tmp.data[tmp.len + 1]) tmp.len++;
    return tmp;
  }
  bignum operator*(long long x) {
    int i;
    bignum tmp;
    for (i = 1; i <= len; ++i) tmp[i] = data[i] * x;
    tmp.len = len;
    for (i = 1; i <= len; ++i) {
      tmp[i + 1] += tmp[i] / base, tmp[i] %= base;
      if (tmp[i + 1] && i + 1 > tmp.len) tmp.len++;
    }
    return tmp;
  }
  bignum operator/(long long x) {
    int i;
    bignum tmp;
    long long y = 0;
    for (i = len; i >= 1; --i) {
      y = y * base + data[i];
      tmp[i] = y / x;
      y %= x;
    }
    tmp.len = len;
    while (tmp[tmp.len] == 0 && tmp.len > 1) tmp.len--;
    return tmp;
  }
  bignum operator/(const bignum &b) {
    if (b.len <= 1 && b[1] == 0) {
      printf("error! 被0除!");
      for (;;)
        ;
    }
    int i, l1 = (len - 1) * Blen, l2 = (b.len - 1) * Blen;
    long long x = data[len], y = b[b.len];
    while (x) x /= 10, l1++;
    while (y) y /= 10, l2++;
    bignum tmp, chu, B;
    chu = *this;
    B = b;
    for (i = 1; i * Blen <= l1 - l2; ++i) B *= base;
    for (i = 1; i <= (l1 - l2) % Blen; ++i) B *= 10;
    for (i = l1 - l2; i >= 0; --i) {
      x = 0;
      while (chu >= B) chu -= B, x++;
      tmp[i / Blen + 1] = tmp[i / Blen + 1] * 10 + x;
      B /= 10;
    }
    tmp.len = (l1 - l2) / Blen + 1;
    while (tmp.len >= 1 && !tmp[tmp.len]) tmp.len--;
    return tmp;
  }
  bignum operator+(const bignum &b) {
    bignum tmp;
    int i, l = max(len, b.len);
    for (i = 1; i <= l; ++i) tmp[i] = data[i] + b[i];
    for (i = 1; i <= l; ++i) tmp[i + 1] += tmp[i] / base, tmp[i] %= base;
    tmp.len = l;
    if (tmp[tmp.len + 1]) tmp.len++;
    return tmp;
  }
  bignum operator+(long long x) {
    bignum tmp;
    tmp = *this;
    tmp[1] += x;
    for (int i = 1; i <= len && tmp[i] >= base; ++i)
      tmp[i + 1] += tmp[i] / base, tmp[i] %= base;
    while (tmp[tmp.len + 1]) tmp.len++;
    return tmp;
  }
  bignum operator-(const bignum &b) {
    int i;
    bignum tmp;
    for (i = 1; i <= len; ++i) tmp.data[i] = data[i] - b.data[i];
    for (i = 1; i <= len; ++i) {
      if (tmp[i] < 0) tmp.data[i] += base, tmp.data[i + 1]--;
    }
    tmp.len = len;
    while (tmp[tmp.len] == 0 && tmp.len > 1) tmp.len--;
    return tmp;
  }
  bignum operator-(long long x) {
    bignum tmp;
    tmp = *this;
    tmp[1] -= x;
    for (int i = 1; i <= len && tmp[i] < 0; ++i) {
      tmp[i + 1] += (tmp[i] + 1) / base - 1;
      tmp[i] = (tmp[i] + 1) % base + base - 1;
    }
    while (!tmp[tmp.len] && tmp.len > 1) tmp.len--;
    return tmp;
  }
  long long operator%(long long x) {
    int i;
    long long y = 0;
    for (i = len; i >= 1; --i) y = (y * base + data[i]) % x;
    return y;
  }
  bignum operator%(const bignum &b) {
    if (b.len <= 1 && b[1] == 0) {
      printf("error! 被0 mod!");
      for (;;)
        ;
    }
    int i, l1 = (len - 1) * Blen, l2 = (b.len - 1) * Blen;
    long long x = data[len], y = b[b.len];
    while (x) x /= 10, l1++;
    while (y) y /= 10, l2++;
    bignum chu, B;
    chu = *this;
    B = b;
    for (i = 1; i * Blen <= l1 - l2; ++i) B *= base;
    for (i = 1; i <= (l1 - l2) % Blen; ++i) B *= 10;
    for (i = l1 - l2; i >= 0; --i) {
      while (chu >= B) chu -= B;
      B /= 10;
    }
    return chu;
  }
  bignum operator+=(const bignum &b) { return *this = (*this + b); }
  bignum operator*=(const bignum &b) { return *this = (*this * b); }
  bignum operator-=(const bignum &b) { return *this = (*this - b); }
  bignum operator/=(const bignum &b) { return *this = (*this / b); }
  bignum operator%=(const bignum &b) { return *this = (*this % b); }
  bignum operator*=(long long x) { return (*this = (*this * x)); }
  bignum operator+=(long long x) { return (*this = (*this + x)); }
  bignum operator-=(long long x) { return (*this = (*this - x)); }
  bignum operator/=(long long x) { return (*this = (*this / x)); }
  void read() {
    char c[bignumlen * Blen + 10];
    scanf("%s", c + 1);
    int l = strlen(c + 1);
    (*this).clear();
    long long x;
    for (int i = 1; i <= (l - 1) / Blen + 1; ++i) {
      x = 0;
      for (int j = l - Blen * i + 1; j <= l - Blen * i + Blen; ++j)
        if (j >= 1) x = x * 10 + c[j] - 48;
      data[++len] = x;
    }
  }
  void write() {
    printf("%lld", data[len]);
    for (int i = len - 1; i >= 1; --i) printf("%0*lld", Blen, data[i]);
    printf("\n");
  }
};
long long track[100];
vector<long long> hap;
void sol(int pos) {
  long long ans = 0;
  long long base = 1;
  for (int i = 0; i < pos; i++) {
    ans += track[i] * base;
    base *= 10;
  }
  if (ans) hap.push_back(ans);
  if (pos == 18) return;
  track[pos] = 4;
  sol(pos + 1);
  track[pos] = 7;
  sol(pos + 1);
}
long long n, k;
struct node {
  long long l, r, len;
  node(long long a = 0, long long b = 0) : l(a), r(b) {}
};
struct val {
  long long q, r;
  val(long long a = 0, long long b = 0) : q(a), r(b) {}
};
const long long MAX = 1e5 + 20, MOD = 1e8;
node ns[MAX];
node ns2[MAX];
bignum zz[MAX], zz2[MAX];
int preY[MAX * 7];
const val operator+(const val &a, const val &b) {
  long long r = a.r + b.r;
  return {a.q + b.q + r / MOD, r % MOD};
}
const val operator*(const val &a, const val &b) {
  long long r = a.r * b.r;
  return {a.q * b.q * MOD + a.q * b.r + b.q * a.r + r / MOD, r % MOD};
}
const val operator-(const val &a, const val &b) {
  long long r = a.r - b.r;
  if (r >= 0)
    return {a.q - b.q, r};
  else {
    assert(r + MOD >= 0 && r + MOD < MOD);
    return {a.q - b.q - 1, r + MOD};
  }
}
bool operator<(const val &a, const val &b) {
  if (a.q != b.q)
    return a.q < b.q;
  else
    return a.r < b.r;
}
bool operator<=(const val &a, const val &b) { return !(b < a); }
void print(const val &v) { printf("v = %lld\n", v.q * MOD + v.r); }
int main() {
  sol(0);
  sort(hap.begin(), hap.end());
  scanf("%lld%lld", &n, &k);
  long long minlen = LLONG_MAX;
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld", &ns[i].l, &ns[i].r);
    ns[i].len = ns[i].r - ns[i].l;
    minlen = min(minlen, ns[i].len);
    ns2[i] = ns[i];
  }
  sort(ns, ns + n, [](const node &a, const node &b) { return a.r < b.r; });
  sort(ns2, ns2 + n, [](const node &a, const node &b) { return a.l < b.l; });
  for (int i = 0; i < n; i++) {
    if (i == 0)
      zz[i] = ns[i].r;
    else
      zz[i] = zz[i - 1] + ns[i].r;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i == n - 1)
      zz2[i] = ns2[i].l;
    else
      zz2[i] = zz2[i + 1] + ns2[i].l;
  }
  for (int i = (int)hap.size() - 1; i >= 0; i--) {
    long long cur = hap[i];
    int l = 0, r = n - 1;
    while (l < r) {
      int mid = (l + r) / 2;
      if (ns2[mid].l >= cur) {
        r = mid;
      } else
        l = mid + 1;
    }
    if (ns2[l].l < cur)
      preY[i] = -1;
    else
      preY[i] = l;
  }
  int ans = 0;
  bignum limit = k;
  for (int last = 0; last < hap.size(); last++) {
    long long cur = hap[last];
    bignum cc = cur;
    int l = 0, r = n - 1;
    bool debug = 0;
    while (l < r) {
      int mid = (l + r + 1) / 2;
      if (ns[mid].r <= cur)
        l = mid;
      else
        r = mid - 1;
    }
    bignum tmp = 0;
    if (ns[l].r <= cur) {
      tmp = cc * (l + 1) - zz[l];
    }
    if (tmp <= limit) {
      bignum resi = limit - tmp;
      int l = 0, r = last;
      while (l < r) {
        int mid = (l + r) / 2;
        if (hap[last] - hap[mid] <= minlen)
          r = mid;
        else
          l = mid + 1;
      }
      int l1 = l, r1 = last;
      if (debug) resi.write();
      while (l1 < r1) {
        int mid = (l1 + r1) / 2;
        int idx = preY[mid];
        bignum cc2 = hap[mid];
        if (idx == -1 || zz2[idx] - cc2 * (n - idx) <= resi)
          r1 = mid;
        else
          l1 = mid + 1;
      }
      int idx = preY[l1];
      bignum cc2 = hap[l1];
      if (idx == -1 || zz2[idx] - cc2 * (n - idx) <= resi) {
        ans = max(last - l1 + 1, ans);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
