#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, w, e, r, t, a[10];
  for (w = 0; w < 10; w++) a[w] = 0;
  char *s = new char[1000001];
  cin >> s;
  for (w = 0; s[w]; w++) a[s[w] - 48]++;
  a[1]--;
  a[6]--;
  a[8]--;
  a[9]--;
  t = 0;
  for (w = 1; w < 10; w++)
    for (e = 0; e < a[w]; e++) {
      t = (t * 10 + w) % 7;
      cout << w;
    }
  if (t == 0)
    cout << 1869;
  else if (t == 1)
    cout << 6198;
  else if (t == 2)
    cout << 1896;
  else if (t == 3)
    cout << 1689;
  else if (t == 4)
    cout << 1986;
  else if (t == 5)
    cout << 1968;
  if (t == 6) cout << 1698;
  for (w = 0; w < a[0]; w++) cout << 0;
  return 0;
}
