#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int cnt[15];
int x[] = {1, 6, 8, 9};
int main() {
  string w;
  cin >> w;
  for (int i = 0; i < w.size(); i++) cnt[w[i] - '0']++;
  cnt[1]--;
  cnt[6]--;
  cnt[8]--;
  cnt[9]--;
  int mod = 0;
  for (int i = 1; i <= 9; i++) {
    while (cnt[i]) {
      cnt[i]--;
      cout << i;
      mod = mod * 10 + i;
      mod %= 7;
    }
  }
  mod *= 10000;
  mod %= 7;
  bool solved = false;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (i == j) continue;
      for (int k = 0; k < 4; k++) {
        if (k == i || k == j) continue;
        for (int p = 0; p < 4; p++) {
          if (p == i || p == j || p == k) continue;
          int gotten = x[i] * 1000;
          gotten += x[j] * 100;
          gotten += x[k] * 10;
          gotten += x[p];
          gotten %= 7;
          if ((gotten + mod) % 7 == 0 && !solved) {
            cout << x[i] << x[j] << x[k] << x[p];
            solved = true;
          }
        }
      }
    }
  }
  while (cnt[0]) {
    cnt[0]--;
    cout << 0;
  }
  return 0;
}
