#include <bits/stdc++.h>
using namespace std;
long long ten[20];
long long a, b, c, st, l;
int m;
int count(long long x) {
  int ret = 0;
  for (; x; x /= 10)
    if (x % 10 == 4 || x % 10 == 7) ret++;
  return ret;
}
long long dec(long long x) {
  for (long long ten = 1;; ten *= 10LL) {
    int y = (x / ten) % 10;
    if (y == 4 || y == 7) return x - x % ten + ten;
  }
}
long long add(long long x, int m, int need) {
  if (ten[m] > x)
    if (m >= need)
      return ten[m] + (ten[need] - 1) / 9 * 4;
    else
      return (ten[need] - 1) / 9 * 4;
  if (x / ten[m] % 10 < 3 && m >= need)
    return x + ten[m] - x % ten[m] + (ten[need] - 1) / 9 * 4;
  if (x / ten[m] % 10 < 4 && m + 1 >= need)
    return x + (4 - x / ten[m] % 10) * ten[m] - x % ten[m] +
           (ten[need - 1] - 1) / 9 * 4;
  if (x / ten[m] % 10 < 4 && m >= need)
    return x + (4 - x / ten[m] % 10) * ten[m] - x % ten[m] +
           (ten[need - 1] - 1) / 9 * 4;
  if (x / ten[m] % 10 == 4 && m >= need + 1)
    return x + ten[m] - x % ten[m] + (ten[need + 1] - 1) / 9 * 4;
  if (x / ten[m] % 10 == 4 && m >= need)
    return x + 3 * ten[m] - x % ten[m] + (ten[need] - 1) / 9 * 4;
  if (x / ten[m] % 10 < 7 && m + 1 >= need)
    return x + (7 - x / ten[m] % 10) * ten[m] - x % ten[m] +
           (ten[need - 1] - 1) / 9 * 4;
  if (x / ten[m] % 10 == 7)
    if (m >= need + 1)
      return x + ten[m] - x % ten[m] + (ten[need + 1] - 1) / 9 * 4;
    else
      return add(x, m + 1, need + 1);
  if (x / ten[m] % 10 < 9 && m >= need)
    return x + ten[m] - x % ten[m] + (ten[need] - 1) / 9 * 4;
  return add(x, m + 1, need);
}
long long inc(long long x) { return add(x, 0, 1); }
int main() {
  cin >> a >> l;
  c = a + l - 1;
  for (ten[0] = 1, m = 1; m < 20; m++) ten[m] = ten[m - 1] * 10LL;
  for (m = 0, b = 0; l >= 10; a /= 10, l /= 10, c /= 10, m++)
    b += (a % 10) * ten[m];
  st = a + 1;
  if (count(st) < count(a)) st = inc(st);
  if (count(st) > count(a)) st = dec(st);
  while (1) {
    bool flag = true;
    for (int i = 0; a + i <= c; i++) {
      while (count(a + i) > count(st + i)) {
        st = inc(st + i) - i;
        flag = false;
      }
      if (!flag) break;
      while (count(a + i) < count(st + i)) {
        st = dec(st + i) - i;
        flag = false;
      }
    }
    if (flag) break;
  }
  cout << st * ten[m] + b << endl;
}

### Prompt

Your challenge is to write 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;
long long ten[20];
long long a, b, c, st, l;
int m;
int count(long long x) {
  int ret = 0;
  for (; x; x /= 10)
    if (x % 10 == 4 || x % 10 == 7) ret++;
  return ret;
}
long long dec(long long x) {
  for (long long ten = 1;; ten *= 10LL) {
    int y = (x / ten) % 10;
    if (y == 4 || y == 7) return x - x % ten + ten;
  }
}
long long add(long long x, int m, int need) {
  if (ten[m] > x)
    if (m >= need)
      return ten[m] + (ten[need] - 1) / 9 * 4;
    else
      return (ten[need] - 1) / 9 * 4;
  if (x / ten[m] % 10 < 3 && m >= need)
    return x + ten[m] - x % ten[m] + (ten[need] - 1) / 9 * 4;
  if (x / ten[m] % 10 < 4 && m + 1 >= need)
    return x + (4 - x / ten[m] % 10) * ten[m] - x % ten[m] +
           (ten[need - 1] - 1) / 9 * 4;
  if (x / ten[m] % 10 < 4 && m >= need)
    return x + (4 - x / ten[m] % 10) * ten[m] - x % ten[m] +
           (ten[need - 1] - 1) / 9 * 4;
  if (x / ten[m] % 10 == 4 && m >= need + 1)
    return x + ten[m] - x % ten[m] + (ten[need + 1] - 1) / 9 * 4;
  if (x / ten[m] % 10 == 4 && m >= need)
    return x + 3 * ten[m] - x % ten[m] + (ten[need] - 1) / 9 * 4;
  if (x / ten[m] % 10 < 7 && m + 1 >= need)
    return x + (7 - x / ten[m] % 10) * ten[m] - x % ten[m] +
           (ten[need - 1] - 1) / 9 * 4;
  if (x / ten[m] % 10 == 7)
    if (m >= need + 1)
      return x + ten[m] - x % ten[m] + (ten[need + 1] - 1) / 9 * 4;
    else
      return add(x, m + 1, need + 1);
  if (x / ten[m] % 10 < 9 && m >= need)
    return x + ten[m] - x % ten[m] + (ten[need] - 1) / 9 * 4;
  return add(x, m + 1, need);
}
long long inc(long long x) { return add(x, 0, 1); }
int main() {
  cin >> a >> l;
  c = a + l - 1;
  for (ten[0] = 1, m = 1; m < 20; m++) ten[m] = ten[m - 1] * 10LL;
  for (m = 0, b = 0; l >= 10; a /= 10, l /= 10, c /= 10, m++)
    b += (a % 10) * ten[m];
  st = a + 1;
  if (count(st) < count(a)) st = inc(st);
  if (count(st) > count(a)) st = dec(st);
  while (1) {
    bool flag = true;
    for (int i = 0; a + i <= c; i++) {
      while (count(a + i) > count(st + i)) {
        st = inc(st + i) - i;
        flag = false;
      }
      if (!flag) break;
      while (count(a + i) < count(st + i)) {
        st = dec(st + i) - i;
        flag = false;
      }
    }
    if (flag) break;
  }
  cout << st * ten[m] + b << endl;
}

```