#include <bits/stdc++.h>
using namespace std;
int ON(int N, int pos) { return N = N | (1 << pos); }
int OFF(int N, int pos) { return N = N & ~(1 << pos); }
bool isON(int N, int pos) { return (bool)(N & (1 << pos)); }
string s;
string ss;
int a[100];
int get() {
  int ret;
  int i = 0, j = 0, k = 0;
  for (i = 0; i < ss.length(); i++) {
    k = k * 10 + ss[i] - '0';
    k %= 7;
  }
  return k;
}
int goget(string ssss) {
  int now = 0, i;
  for (i = 0; i < 4; i++) {
    now = now * 10 + ssss[i] - '0';
  }
  return now;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tc, cs;
  int i, j, k;
  cin >> s;
  for (i = 0; i < s.length(); i++) {
    a[s[i] - '0']++;
  }
  a[1]--;
  a[6]--;
  a[8]--;
  a[9]--;
  for (i = 1; i < 10; i++) {
    for (j = 0; j < a[i]; j++) ss += (i + '0');
  }
  int m = get();
  string sss = "1689";
  int f = 0;
  do {
    int x = goget(sss);
    if ((m * 10000 + x) % 7 == 0) {
      f = 1;
      ss += sss;
      break;
    }
  } while (next_permutation(sss.begin(), sss.end()));
  if (!f) {
    cout << 0 << endl;
    return 0;
  }
  for (i = 0; i < a[0]; i++) ss += "0";
  cout << ss << endl;
  return 0;
}
