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;
template <typename T>
inline long long toLong(T a) {
  long long res;
  istringstream os(a);
  os >> res;
  return res;
}
template <typename T>
inline int toInt(T a) {
  int res;
  istringstream os(a);
  os >> res;
  return res;
}
template <typename T>
inline double toDouble(T a) {
  double res;
  istringstream os(a);
  os >> res;
  return res;
}
template <typename T>
inline T SQ(T a) {
  return a * a;
}
template <typename T>
inline T GCD(T a, T b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
template <typename T>
inline T LCM(T a, T b) {
  long long res = a * b;
  res /= GCD(a, b);
  return res;
}
template <typename T>
inline unsigned long long BIGMOD(T a, T b, T m) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return SQ(BIGMOD(a, b / 2, m)) % m;
  else
    return (a % m * BIGMOD(a, b - 1, m)) % m;
}
template <typename T>
inline unsigned long long DIST(T A, T B) {
  unsigned long long res =
      (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);
  return res;
}
template <typename T>
inline long long CROSS(T A, T B, T C) {
  return (B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y);
}
template <typename T>
inline double cosAngle(T a, T b, T c) {
  double res = a * a + b * b - c * c;
  res = res / (2 * a * b);
  res = acos(res);
  return res;
}
template <typename T>
inline T POWER(T base, int po) {
  T res = 1;
  if (base == 0) return 0;
  for (int i = (0); i < (po); i++) res *= base;
  return res;
}
template <typename T>
inline bool IS_ON(T mask, T pos) {
  return mask & (1 << pos);
}
template <typename T>
inline int OFF(T mask, T pos) {
  return mask ^ (1 << pos);
}
template <typename T>
inline int ON(T mask, T pos) {
  return mask | (1 << pos);
}
template <typename T>
inline bool INSIDE_GRID(int R, int C, int ro, int clm) {
  if (R >= 0 && C >= 0 && R < ro && C < clm) return 1;
  return 0;
}
template <typename T>
inline void PRINT_GRID(T GRID, int ro, int clm) {
  cout << "GRID"
       << ": " << GRID << endl;
  for (int i = (0); i < (ro); i++) {
    for (int j = (0); j < (clm); j++) cout << GRID[i][j] << " ";
    puts("");
  }
}
int vis[1000002];
int taken[12];
string str;
vector<string> rese;
int main() {
  cin >> str;
  int n = str.size();
  int cnt = 0;
  for (int i = (0); i < (n); i++) {
    if (str[i] == '1' && vis[i] == 0 && taken[str[i] - '0'] == 0) {
      taken[str[i] - '0'] = 1;
      vis[i] = 1;
    } else if (str[i] == '6' && vis[i] == 0 && taken[str[i] - '0'] == 0) {
      taken[str[i] - '0'] = 1;
      vis[i] = 1;
    } else if (str[i] == '8' && vis[i] == 0 && taken[str[i] - '0'] == 0) {
      taken[str[i] - '0'] = 1;
      vis[i] = 1;
    } else if (str[i] == '9' && vis[i] == 0 && taken[str[i] - '0'] == 0) {
      taken[str[i] - '0'] = 1;
      vis[i] = 1;
    }
    if (str[i] == '0') cnt++;
  }
  string str2 = "1689";
  bool ok = 0;
  if (cnt && cnt + 4 == n) {
    cout << "1869";
    ok = 1;
  }
  int mod = 0, nmod = 0;
  string str3 = "";
  for (int i = (0); i < (n); i++)
    if (!vis[i]) {
      if (!nmod && str[i] == '0') {
        str3 += '0';
        continue;
      }
      printf("%c", str[i]);
      nmod = 1;
      mod = mod * 10 + str[i] - '0';
      mod %= 7;
    }
  if (!ok) do {
      nmod = mod;
      for (int i = (0); i < (4); i++) {
        mod = mod * 10 + str2[i] - '0';
        mod %= 7;
      }
      if (mod == 0) {
        cout << str2;
        break;
      }
      mod = nmod;
    } while (next_permutation((str2).begin(), (str2).end()));
  cout << str3 << endl;
  return 0;
}
