#include <bits/stdc++.h>
using namespace std;
int main() {
  int div[] = {8169, 1968, 1689, 6198, 8691, 9168, 8196, 8169};
  string s;
  cin >> s;
  int f[11] = {0}, n = (int)s.size();
  for (int i = 0; i < n; i++) f[(s[i] - '0')]++;
  f[1]--;
  f[8]--;
  f[9]--;
  f[6]--;
  int rem = 0;
  for (int i = 1; i < 10; i++)
    for (int j = 0; j < f[i]; j++) {
      cout << i;
      rem = rem * 10 + i;
      rem = rem % 7;
    }
  rem *= 10000;
  rem = rem % 7;
  cout << div[7 - rem];
  for (int i = 0; i < f[0]; i++) cout << 0;
  return cout << endl, 0;
}
