#include <bits/stdc++.h>
using namespace std;
char cad[1000009];
int falta[] = {1869, 1968, 6918, 6891, 8691, 9168, 1896};
int cant[50];
int resto[] = {1, 3, 2, 6, 4, 5};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long x = 1;
  cin >> cad;
  int len = strlen(cad);
  for (int i = 0; i < len; i++) {
    cant[cad[i] - 48]++;
  }
  if (cant[0] == len - 4) {
    cout << 1869;
    for (int i = 0; i < cant[0]; i++) {
      cout << 0;
    }
    cout << '\n';
    return 0;
  }
  cant[1]--;
  cant[6]--;
  cant[8]--;
  cant[9]--;
  int res = 0;
  int pos = len - 1;
  for (int i = 1; i <= 9; i++) {
    for (int j = 0; j < cant[i]; j++) {
      res += resto[pos % 6] * i;
      res %= 7;
      pos--;
      cout << i;
    }
  }
  for (int i = 0; i < cant[0]; i++) {
    cout << 0;
  }
  cout << falta[(7 - res) % 7] << '\n';
  return 0;
}
