#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000, INF = 1000000000;
const double eps = 1e-9;
int checko[maxn];
inline int checks(int now) {
  int res = 0;
  while (now) res += ((now % 10 == 4) || (now % 10 == 7)), now /= 10;
  return res;
}
inline int check(int now) { return checko[now % maxn] + checko[now / maxn]; }
inline bool eq(int now, int now1, int l) {
  for (int i = 0; i < l; ++i)
    if (check(now + i) != check(now1 + i)) return 0;
  return 1;
}
inline int hm(int now) {
  int res = 1;
  while (now % 10 == 9) res *= 10, now /= 10;
  return res;
}
inline int get(int l, int len) {
  int r = l + len - 1;
  int pres = (l % 10 == 0);
  l += 9 - ((l + 10 - 1) % 10);
  if (l > r) return 1 - pres;
  if (l == r) return 2 - pres;
  ++l;
  return ((r - l + 1) / 10) + 2 - pres;
}
int next(int first) {
  int k = 0, now = 0;
  while (first % 10 == 4 || first % 10 == 7) {
    if (first % 10 == 7) now = now | (1 << k);
    first /= 10, ++k;
  }
  ++now;
  if (now < (1 << k)) {
    for (int i = k - 1; i >= 0; --i)
      if (now & (1 << i))
        first = first * 10 + 7;
      else
        first = first * 10 + 4;
    return first;
  }
  int t = k;
  if (check(first + 1) - check(first)) {
    k -= check(first + 1) - check(first);
    ++first;
    while (t > k) first *= 10, --t;
    while (t < k) first /= 10, ++t;
  } else
    ++first;
  for (int i = 0; i < k; ++i) first = first * 10 + 4;
  return first;
}
int solve(int nowf, int l) {
  if (nowf < 10) {
    long long pc = l + nowf - 1;
    while (pc >= 10) pc /= 10;
    if (l > 555) {
      long long st = 1;
      while (st <= nowf + l - 1) st *= 10;
      if (pc < 4) st /= 10;
      return st + nowf;
    }
    for (int j = nowf + 1;; ++j)
      if (eq(nowf, j, l)) return j;
  } else if (l <= 5) {
    int now = nowf;
    int need = check(now);
    while (1) {
      if (now != nowf) {
        if (eq(nowf, now, l)) {
          return now;
        }
      }
      if (check(now + 1) == need)
        ++now;
      else if (now % 10 == 3 || now % 10 == 6)
        now += 2;
      else if (now % 10 == 4 || now % 10 == 7)
        now = next(now);
      else if (check(now + 3) == need)
        now += 3;
      else if (check(now + 5) == need)
        now += 5;
      else
        now += hm(now) + 1;
    }
  } else
    return solve(nowf / 10, get(nowf, l)) * 10 + (nowf % 10);
}
int main() {
  for (int i = 0; i < maxn; ++i) checko[i] = checks(i);
  int s, l;
  cin >> s >> l;
  cout << solve(s, l);
}

### Prompt

Please provide a Cpp coded solution to the problem described below:

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 maxn = 100000, INF = 1000000000;
const double eps = 1e-9;
int checko[maxn];
inline int checks(int now) {
  int res = 0;
  while (now) res += ((now % 10 == 4) || (now % 10 == 7)), now /= 10;
  return res;
}
inline int check(int now) { return checko[now % maxn] + checko[now / maxn]; }
inline bool eq(int now, int now1, int l) {
  for (int i = 0; i < l; ++i)
    if (check(now + i) != check(now1 + i)) return 0;
  return 1;
}
inline int hm(int now) {
  int res = 1;
  while (now % 10 == 9) res *= 10, now /= 10;
  return res;
}
inline int get(int l, int len) {
  int r = l + len - 1;
  int pres = (l % 10 == 0);
  l += 9 - ((l + 10 - 1) % 10);
  if (l > r) return 1 - pres;
  if (l == r) return 2 - pres;
  ++l;
  return ((r - l + 1) / 10) + 2 - pres;
}
int next(int first) {
  int k = 0, now = 0;
  while (first % 10 == 4 || first % 10 == 7) {
    if (first % 10 == 7) now = now | (1 << k);
    first /= 10, ++k;
  }
  ++now;
  if (now < (1 << k)) {
    for (int i = k - 1; i >= 0; --i)
      if (now & (1 << i))
        first = first * 10 + 7;
      else
        first = first * 10 + 4;
    return first;
  }
  int t = k;
  if (check(first + 1) - check(first)) {
    k -= check(first + 1) - check(first);
    ++first;
    while (t > k) first *= 10, --t;
    while (t < k) first /= 10, ++t;
  } else
    ++first;
  for (int i = 0; i < k; ++i) first = first * 10 + 4;
  return first;
}
int solve(int nowf, int l) {
  if (nowf < 10) {
    long long pc = l + nowf - 1;
    while (pc >= 10) pc /= 10;
    if (l > 555) {
      long long st = 1;
      while (st <= nowf + l - 1) st *= 10;
      if (pc < 4) st /= 10;
      return st + nowf;
    }
    for (int j = nowf + 1;; ++j)
      if (eq(nowf, j, l)) return j;
  } else if (l <= 5) {
    int now = nowf;
    int need = check(now);
    while (1) {
      if (now != nowf) {
        if (eq(nowf, now, l)) {
          return now;
        }
      }
      if (check(now + 1) == need)
        ++now;
      else if (now % 10 == 3 || now % 10 == 6)
        now += 2;
      else if (now % 10 == 4 || now % 10 == 7)
        now = next(now);
      else if (check(now + 3) == need)
        now += 3;
      else if (check(now + 5) == need)
        now += 5;
      else
        now += hm(now) + 1;
    }
  } else
    return solve(nowf / 10, get(nowf, l)) * 10 + (nowf % 10);
}
int main() {
  for (int i = 0; i < maxn; ++i) checko[i] = checks(i);
  int s, l;
  cin >> s >> l;
  cout << solve(s, l);
}

```