#include <bits/stdc++.h>
using namespace std;
string s;
int a[15];
int b[7] = {1869, 6198, 1896, 1689, 1986, 1968, 1698};
int main() {
  cin >> s;
  memset(a, 0, sizeof(a));
  for (int i = 0; i < s.size(); i++) {
    a[s[i] - '0']++;
  }
  a[1]--;
  a[6]--;
  a[8]--;
  a[9]--;
  int ans = 0;
  for (int i = 1; i <= 9; i++) {
    while (a[i]) {
      ans = (ans * 10 + i) % 7;
      a[i]--;
      cout << i;
    }
  }
  cout << b[ans];
  while (a[0]) {
    cout << "0";
    a[0]--;
  }
  cout << endl;
  return 0;
}
