You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7.

Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resulting number also mustn't contain any leading zeroes.

Input

The first line contains positive integer a in the decimal record. It is guaranteed that the record of number a contains digits: 1, 6, 8, 9. Number a doesn't contain any leading zeroes. The decimal representation of number a contains at least 4 and at most 106 characters.

Output

Print a number in the decimal notation without leading zeroes — the result of the permutation.

If it is impossible to rearrange the digits of the number a in the required manner, print 0.

Examples

Input

1689


Output

1869


Input

18906


Output

18690
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e14 + 9;
long long mult(long long a, long long b) { return a * b % 7; }
long long fastpow(long long a, long long b) {
  long long calc = 1;
  for (; b >= 1LL; b /= 2LL) {
    if ((b & 1LL)) calc = mult(calc, a);
    a = mult(a, a);
  }
  return calc;
}
long long soma(long long a, long long b) {
  if (a + b > 7)
    return a + b - 7;
  else
    return a + b;
}
long long subt(long long a, long long b) {
  if (a - b < 0)
    return a - b + 7;
  else
    return a - b;
}
char vet[4] = {'1', '6', '8', '9'};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string t;
  cin >> t;
  long long soma = 0;
  long long soma2 = 0;
  long long cont1 = 1, cont6 = 1, cont8 = 1, cont9 = 1, cont0 = 0;
  vector<char> nonzero;
  long long cont = 0;
  sort(begin(t), end(t));
  string meio = "";
  for (long long i = 0; i < ((long long)(t).size()); ++i) {
    if (t[i] == '1') {
      if (cont1)
        cont1--;
      else {
        nonzero.push_back(t[i]);
        cont++;
      }
    } else if (t[i] == '6') {
      if (cont6)
        cont6--;
      else {
        nonzero.push_back(t[i]);
        cont++;
      }
    } else if (t[i] == '8') {
      if (cont8)
        cont8--;
      else {
        nonzero.push_back(t[i]);
        cont++;
      }
    } else if (t[i] == '9') {
      if (cont9)
        cont9--;
      else {
        nonzero.push_back(t[i]);
        cont++;
      }
    } else {
      cont++;
      if (t[i] == '0')
        cont0++;
      else {
        nonzero.push_back(t[i]);
      }
    }
  }
  soma = 0;
  soma2 = 0;
  cont1 = 1, cont6 = 1, cont8 = 1, cont9 = 1;
  cont = 0;
  long long pow = fastpow(10, 4 + cont0);
  for (long long i = 0; i < ((long long)(nonzero).size()); ++i) {
    meio += nonzero[i];
    soma2 = (soma2 + ((nonzero[i] - '0') * pow) % 7) % 7;
    pow = (pow * 10) % 7;
  }
  reverse(begin(meio), end(meio));
  string ans = "";
  long long pow2 = fastpow(10, cont0);
  long long pow3 = fastpow(10, cont0 + 1);
  long long pow4 = fastpow(10, cont0 + 2);
  long long pow5 = fastpow(10, cont0 + 3);
  string ansf;
  for (long long i = 0; i < (4); ++i) {
    long long somaantes = soma;
    string ansr = ans;
    soma = (soma + ((vet[i] - '0') * pow5) % 7) % 7;
    ans += vet[i];
    for (long long j = 0; j < (4); ++j) {
      if (i == j) continue;
      string ansr2 = ans;
      long long somaantes2 = soma;
      soma = (soma + ((vet[j] - '0') * pow4) % 7) % 7;
      ans += vet[j];
      for (long long k = 0; k < (4); ++k) {
        if (k == i || k == j) continue;
        string ansr3 = ans;
        long long somaantes3 = soma;
        soma = (soma + ((vet[k] - '0') * pow3) % 7) % 7;
        ans += vet[k];
        for (long long w = 0; w < (4); ++w) {
          string ansr4 = ans;
          if (w == i || w == j || w == k) continue;
          long long somaantes4 = soma;
          soma = (soma + ((vet[w] - '0') * pow2) % 7) % 7;
          ans += vet[w];
          if (soma == 7 - soma2 || (soma2 == 0 && soma == 0)) ansf = ans;
          soma = somaantes4;
          ans = ansr4;
        }
        soma = somaantes3;
        ans = ansr3;
      }
      soma = somaantes2;
      ans = ansr2;
    }
    soma = somaantes;
    ans = ansr;
  }
  string ansfinal = meio + ansf;
  for (long long i = 0; i < (cont0); ++i) ansfinal += '0';
  cout << ansfinal << "\n";
  return 0;
}
