#include <bits/stdc++.h>
using namespace std;
string s;
int cnt[11];
int main() {
  ios ::sync_with_stdio(false);
  cout << (fixed) << setprecision(9);
  while (cin >> s) {
    memset(cnt, 0, sizeof cnt);
    for (char c : s) cnt[c - '0']++;
    vector<int> a;
    --cnt[1];
    --cnt[6];
    --cnt[8];
    --cnt[9];
    int rem = 0;
    for (int i = (1), _b = (9); i <= _b; i++) {
      while (cnt[i]) {
        a.push_back(i);
        --cnt[i];
        rem = (rem * 10 + i) % 7;
      }
    }
    rem = (rem * 10000) % 7;
    int x[4] = {1, 6, 8, 9};
    do {
      int cur = 0;
      for (int i = 0, _a = (4); i < _a; i++) cur = (cur * 10 + x[i]) % 7;
      if ((rem + cur) % 7 == 0) {
        break;
      }
    } while (next_permutation(x, x + 4));
    for (int x : a) cout << x;
    for (int t = 0, _a = (4); t < _a; t++) cout << x[t];
    while (cnt[0]) {
      cout << 0;
      --cnt[0];
    }
    cout << endl;
  }
  return 0;
}
