#include <bits/stdc++.h>
using namespace std;
int mods[7] = {1869, 6198, 1896, 1689, 1986, 8961, 1698};
int ct[10];
string s;
int main() {
  int num = 0;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    ct[s[i] - '0']++;
  }
  ct[1]--;
  ct[6]--;
  ct[8]--;
  ct[9]--;
  for (int i = 1; i < 10; i++) {
    while (ct[i]) {
      cout << i;
      num = 10 * num + i;
      num %= 7;
      ct[i]--;
    }
  }
  cout << mods[num];
  for (int i = 0; i < ct[0]; i++) {
    cout << 0;
  }
}
