#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 1;
long long powmod(long long x, long long y, long long p = 7) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int pa[M];
int main() {
  string s = "1689";
  int a[7]{0};
  do {
    int r = stoi(s);
    a[r % 7] = r;
  } while (next_permutation(s.begin(), s.end()));
  cin >> s;
  vector<string> v;
  for (int i = 0; i < 7; i++) {
    v.push_back(to_string(a[i]));
  }
  int cnt[10]{0};
  for (char c : s) {
    cnt[c - '0']++;
  }
  cnt[9]--;
  cnt[1]--;
  cnt[6]--;
  cnt[8]--;
  int Ans = 0;
  int p = 1;
  int z = 4;
  string S;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < cnt[i]; j++) {
      Ans += (i % 7 * powmod(10, z++)) % 7;
      Ans %= 7;
      S.push_back(i + '0');
    }
  }
  sort(S.rbegin(), S.rend());
  if (S[0] != '0') {
    for (int i = 0; i < 7; i++) {
      if ((Ans + i) % 7 == 0) {
        cout << S << v[i];
        return 0;
      }
    }
  } else {
    cout << v[0] << S;
  }
}
