#include <bits/stdc++.h>
using namespace std;
vector<int> d, cnt;
string s;
int n, ans[10];
int main() {
  d.push_back(1);
  d.push_back(6);
  d.push_back(8);
  d.push_back(9);
  while (next_permutation(d.begin(), d.end())) {
    n = d[0] * 1000 + d[1] * 100 + d[2] * 10 + d[3];
    ans[n % 7] = n;
  }
  cnt = vector<int>(10, 0);
  cin >> s;
  for (int i = 0; i < (int)(s.size()); i += 1) {
    cnt[s[i] - '0']++;
  }
  cnt[1]--, cnt[6]--, cnt[8]--, cnt[9]--;
  if (cnt[0] + 4 == (int)(s.size())) {
    cout << ans[0];
    for (int i = 0; i < cnt[0]; i += 1) {
      cout << 0;
    }
    cout << '\n';
  } else {
    int a = 0;
    for (int i = 9; i >= 0; i -= 1) {
      for (int j = 0; j < cnt[i]; j += 1) {
        a = (10 * a + i) % 7;
        cout << i;
      }
    }
    a = (10000 * a) % 7;
    a = (7 - a) % 7;
    cout << ans[a] << '\n';
  }
  return 0;
}
