#include <bits/stdc++.h>
using namespace std;
const int N = 19;
long long pw10[N];
inline int countLucky(long long n) {
  int ret = 0;
  while (n) {
    if (n % 10 == 4 || n % 10 == 7) ret++;
    n /= 10;
  }
  return ret;
}
int digCnt(long long n) {
  int ret = 0;
  while (n) {
    ret++;
    n /= 10;
  }
  return ret;
}
vector<int> dig;
long long mem[N][N], aa;
long long func(int ind, int till, int req, int flg, long long cur,
               long long sf) {
  if (ind == till) {
    if (req != 0) return -2;
    if (flg && cur + sf <= aa) return -2;
    return cur + sf;
  }
  if (!flg) {
    if (mem[ind][req] != -1) return mem[ind][req];
  }
  long long ret = -2;
  for (int d = 0; d <= 9; d++) {
    if (flg && dig[ind] > d) continue;
    if (req == 0 && (d == 4 || d == 7)) continue;
    long long tmp = func(ind - 1, till, req - ((d == 4 || d == 7) ? 1 : 0),
                         flg && (d == dig[ind]), cur + pw10[ind] * d, sf);
    if (tmp != -2) {
      if (ret == -2)
        ret = tmp;
      else
        ret = min(ret, tmp);
    }
  }
  if (!flg) mem[ind][req] = ret;
  return ret;
}
long long compute(long long lo, long long hi) {
  int len = hi - lo + 1;
  vector<int> v(len);
  for (long long i = lo; i <= hi; i++) {
    v[i - lo] = countLucky(i);
  }
  if (lo <= 10) {
    for (int b = lo + 1; b <= 100; b++) {
      bool flg = true;
      for (int i = 0; i < len; i++) {
        if (countLucky(b + i) != v[i]) {
          flg = false;
          break;
        }
      }
      if (flg) return b;
    }
    assert(false);
  }
  int dc = digCnt(lo);
  long long ret = pw10[dc] + lo;
  dig.clear();
  for (int i = 0; i < dc; i++) {
    dig.push_back((lo / pw10[i]) % 10);
  }
  aa = lo;
  for (int d = 0; d < 10; d++) {
    for (int n9 = 0; n9 + 2 <= dc; n9++) {
      for (int k = 0; k < 9; k++) {
        int cnt = countLucky(d) + countLucky(k);
        if (cnt > v[0]) continue;
        long long suf = k;
        for (int i = 0; i < n9; i++) {
          suf = suf * 10 + 9;
        }
        suf = suf * 10 + d;
        bool flg = true;
        for (int i = 0; i < len; i++) {
          if (v[i] - countLucky(suf + i) != v[0] - cnt) {
            flg = false;
            break;
          }
        }
        if (!flg) continue;
        memset(mem, -1, sizeof(mem));
        long long tmp = func(dc - 1, n9 + 1, v[0] - cnt, 1, 0, suf);
        if (tmp != -2) ret = min(ret, tmp);
      }
    }
  }
  for (int d = 0; d < 10; d++) {
    for (int n9 = 0; n9 + 2 <= dc; n9++) {
      for (int k = 0; k < 9; k++) {
        int cnt = countLucky(d) + countLucky(k);
        if (cnt > v[0]) continue;
        long long suf = k;
        for (int i = 0; i < n9; i++) {
          suf = suf * 10 + 9;
        }
        suf = suf * 10 + d;
        bool flg = true;
        for (int i = 0; i < len; i++) {
          if (v[i] - countLucky(suf + i) != v[0] - cnt) {
            flg = false;
            break;
          }
        }
        if (!flg) continue;
        memset(mem, -1, sizeof(mem));
        long long tmp = func(dc - 1, n9 + 1, v[0] - cnt, 0, pw10[dc], suf);
        if (tmp != -2) ret = min(ret, tmp);
      }
    }
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(32);
  pw10[0] = 1;
  for (int i = 1; i < N; i++) {
    pw10[i] = pw10[i - 1] * 10;
  }
  long long a, l;
  cin >> a >> l;
  long long pw = 1;
  while (pw * 10 <= l) pw *= 10;
  long long ans = compute(a / pw, (a + l - 1) / pw) * pw + (a % pw);
  cout << ans << '\n';
  return 0;
}

### Prompt

Please formulate a cpp solution to the following problem:

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

One day Petya came across an interval of numbers [a, a + l - 1]. Let F(x) be the number of lucky digits of number x. Find the minimum b (a < b) such, that F(a) = F(b), F(a + 1) = F(b + 1), ..., F(a + l - 1) = F(b + l - 1).

Input

The single line contains two integers a and l (1 ≤ a, l ≤ 109) — the interval's first number and the interval's length correspondingly.

Output

On the single line print number b — the answer to the problem.

Examples

Input

7 4


Output

17


Input

4 7


Output

14

Note

Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 19;
long long pw10[N];
inline int countLucky(long long n) {
  int ret = 0;
  while (n) {
    if (n % 10 == 4 || n % 10 == 7) ret++;
    n /= 10;
  }
  return ret;
}
int digCnt(long long n) {
  int ret = 0;
  while (n) {
    ret++;
    n /= 10;
  }
  return ret;
}
vector<int> dig;
long long mem[N][N], aa;
long long func(int ind, int till, int req, int flg, long long cur,
               long long sf) {
  if (ind == till) {
    if (req != 0) return -2;
    if (flg && cur + sf <= aa) return -2;
    return cur + sf;
  }
  if (!flg) {
    if (mem[ind][req] != -1) return mem[ind][req];
  }
  long long ret = -2;
  for (int d = 0; d <= 9; d++) {
    if (flg && dig[ind] > d) continue;
    if (req == 0 && (d == 4 || d == 7)) continue;
    long long tmp = func(ind - 1, till, req - ((d == 4 || d == 7) ? 1 : 0),
                         flg && (d == dig[ind]), cur + pw10[ind] * d, sf);
    if (tmp != -2) {
      if (ret == -2)
        ret = tmp;
      else
        ret = min(ret, tmp);
    }
  }
  if (!flg) mem[ind][req] = ret;
  return ret;
}
long long compute(long long lo, long long hi) {
  int len = hi - lo + 1;
  vector<int> v(len);
  for (long long i = lo; i <= hi; i++) {
    v[i - lo] = countLucky(i);
  }
  if (lo <= 10) {
    for (int b = lo + 1; b <= 100; b++) {
      bool flg = true;
      for (int i = 0; i < len; i++) {
        if (countLucky(b + i) != v[i]) {
          flg = false;
          break;
        }
      }
      if (flg) return b;
    }
    assert(false);
  }
  int dc = digCnt(lo);
  long long ret = pw10[dc] + lo;
  dig.clear();
  for (int i = 0; i < dc; i++) {
    dig.push_back((lo / pw10[i]) % 10);
  }
  aa = lo;
  for (int d = 0; d < 10; d++) {
    for (int n9 = 0; n9 + 2 <= dc; n9++) {
      for (int k = 0; k < 9; k++) {
        int cnt = countLucky(d) + countLucky(k);
        if (cnt > v[0]) continue;
        long long suf = k;
        for (int i = 0; i < n9; i++) {
          suf = suf * 10 + 9;
        }
        suf = suf * 10 + d;
        bool flg = true;
        for (int i = 0; i < len; i++) {
          if (v[i] - countLucky(suf + i) != v[0] - cnt) {
            flg = false;
            break;
          }
        }
        if (!flg) continue;
        memset(mem, -1, sizeof(mem));
        long long tmp = func(dc - 1, n9 + 1, v[0] - cnt, 1, 0, suf);
        if (tmp != -2) ret = min(ret, tmp);
      }
    }
  }
  for (int d = 0; d < 10; d++) {
    for (int n9 = 0; n9 + 2 <= dc; n9++) {
      for (int k = 0; k < 9; k++) {
        int cnt = countLucky(d) + countLucky(k);
        if (cnt > v[0]) continue;
        long long suf = k;
        for (int i = 0; i < n9; i++) {
          suf = suf * 10 + 9;
        }
        suf = suf * 10 + d;
        bool flg = true;
        for (int i = 0; i < len; i++) {
          if (v[i] - countLucky(suf + i) != v[0] - cnt) {
            flg = false;
            break;
          }
        }
        if (!flg) continue;
        memset(mem, -1, sizeof(mem));
        long long tmp = func(dc - 1, n9 + 1, v[0] - cnt, 0, pw10[dc], suf);
        if (tmp != -2) ret = min(ret, tmp);
      }
    }
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << setprecision(32);
  pw10[0] = 1;
  for (int i = 1; i < N; i++) {
    pw10[i] = pw10[i - 1] * 10;
  }
  long long a, l;
  cin >> a >> l;
  long long pw = 1;
  while (pw * 10 <= l) pw *= 10;
  long long ans = compute(a / pw, (a + l - 1) / pw) * pw + (a % pw);
  cout << ans << '\n';
  return 0;
}

```