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