#include <bits/stdc++.h>
using namespace std;
const int inf_int = 0x3f3f3f3f;
const long long inf_ll = 0x7f7f7f7f7f7f7f7f;
const int maxn = 1e4 + 10;
inline int read() {
  int x = 0, f = 1, ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - 48;
    ch = getchar();
  }
  return x * f;
}
string s;
bool ok[10];
vector<int> v, r;
int a[4] = {1, 6, 8, 9};
int sum() {
  int res = 0;
  for (int i = 0; i < 4; i++) res = res * 10 + a[i];
  return res % 7;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> s;
  int len = s.size();
  for (int i = 0; i < len; i++) {
    int t = s[i] - '0';
    if ((t == 1) && !ok[t])
      ok[t] = 1;
    else if ((t == 6) && !ok[t])
      ok[t] = 1;
    else if ((t == 8) && !ok[t])
      ok[t] = 1;
    else if ((t == 9) && !ok[t])
      ok[t] = 1;
    else if (t == 0)
      r.push_back(0);
    else
      v.push_back(t);
  }
  int mod = 0;
  for (int i = 0; i < v.size(); i++) mod = (mod * 10 + v[i]) % 7;
  for (int i = 0; i < 4; i++) mod = (mod * 10) % 7;
  bool book = 0;
  do {
    if ((mod + sum()) % 7 == 0) {
      for (int i = 0; i < v.size(); i++) cout << v[i];
      for (int i = 0; i < 4; i++) cout << a[i];
      for (int i = 0; i < r.size(); i++) cout << r[i];
      return 0;
    }
  } while (next_permutation(a, a + 4));
  cout << 0 << '\n';
  return 0;
}
