#include <bits/stdc++.h>
using namespace std;
int a[11], d[8];
int main() {
  string s;
  cin >> s;
  int n = s.length();
  for (int i = 0; i < n; i++) {
    a[s[i] - '0']++;
  }
  for (int mod = 0; mod < 7; mod++) {
    int b[] = {1, 6, 8, 9};
    do {
      int x = mod, y = 0;
      for (int i = 0; i < 4; i++) {
        x = x * 10 + b[i];
        y = y * 10 + b[i];
      }
      if (x % 7 == 0) d[mod] = y;
    } while (next_permutation(b, b + 4));
  }
  a[1]--;
  a[6]--;
  a[8]--;
  a[9]--;
  int rem = 0;
  for (int i = 1; i <= 9; i++) {
    while (a[i] > 0) {
      cout << i;
      rem = rem * 10 + i;
      rem %= 7;
      a[i]--;
    }
  }
  cout << d[rem];
  while (a[0] > 0) {
    cout << 0;
    a[0]--;
  }
}
