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;
void customrun() {}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool isprime(long long n) {
  for (long long i = 2; (long long)i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long fib(int n) {
  long long a = 0, b = 1, c, i;
  if (n == 0) return a;
  for (i = 2; i <= n; i++) {
    c = (a + b);
    a = b;
    b = c;
  }
  return b;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long extendedgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long d = extendedgcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}
long long findgrouplcm(vector<int> &arr, int n) {
  long long ans = arr[0];
  for (long long i = 1; i < n; i++) ans = (arr[i] * (ans / (gcd(arr[i], ans))));
  return ans;
}
long long powerwithmod(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool comp(const pair<long, long> &a, const pair<long, long> &b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
void solve();
int main() {
  clock_t begin = clock();
  fast();
  customrun();
  long long t = 1;
  for (long long i = (1); i < (t + 1); i += (1)) {
    solve();
  }
  clock_t end = clock();
  return 0;
}
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long temp = power(a, b / 2);
  temp *= temp;
  if (b & 1) temp *= a;
  return temp;
}
void solve() {
  string num;
  cin >> (num);
  int n = num.size(), fre[10] = {0};
  for (long long i = 0; i < n; i++) {
    fre[num[i] - '0']++;
  }
  string res = "";
  for (long long i = (1); i < (10); i += (1)) {
    if (i == 1 or i == 6 or i == 8 or i == 9) {
      for (long long j = 0; j < fre[i] - 1; j++) {
        res += (i + '0');
      }
    } else {
      for (long long j = 0; j < fre[i]; j++) {
        res += (i + '0');
      }
    }
  }
  string l = "1689";
  vector<string> v;
  string zero = "";
  for (long long i = 0; i < fre[0]; i++) zero += '0';
  do {
    string temp = (res + l + zero);
    v.push_back(temp);
  } while (next_permutation(l.begin(), l.end()));
  for (long long i = 0; i < v.size(); i++) {
    long long p = 0;
    for (long long j = 0; j < n; j++) {
      p = p * 10 + (v[i][j] - '0');
      p = p % 7;
    }
    if (p == 0) {
      cout << (v[i]);
      return;
    }
  }
}
