#include <bits/stdc++.h>
template <typename T>
inline T sqr(T a) {
  return a * a;
}
const long double pi = acos(-1.0);
using namespace std;
int cnt[10];
int main() {
  ios_base::sync_with_stdio(0);
  string s;
  cin >> s;
  for (int i = 0; i < (int)s.size(); i++) {
    cnt[s[i] - '0']++;
  }
  cnt[1]--;
  cnt[6]--;
  cnt[8]--;
  cnt[9]--;
  string ans = "";
  int mod7 = 0;
  for (int i = 1; i <= 9; i++) {
    while (cnt[i] > 0) {
      ans += char('0' + i);
      mod7 = (mod7 * 10 + i) % 7;
      cnt[i]--;
    }
  }
  vector<int> a = {1, 6, 8, 9};
  string add = "";
  for (int i = 0; i <= 3; i++) {
    for (int j = 0; j <= 3; j++) {
      for (int k = 0; k <= 3; k++) {
        if (i == j || i == k || j == k) continue;
        int t = 6 - i - j - k;
        if (((((mod7 * 10 + a[i]) * 10 + a[j]) * 10 + a[k]) * 10 + a[t]) % 7 ==
            0) {
          add = "";
          add += char(a[i] + '0');
          add += char(a[j] + '0');
          add += char(a[k] + '0');
          add += char(a[t] + '0');
        }
      }
    }
  }
  ans += add;
  while (cnt[0] > 0) {
    ans += '0';
    cnt[0]--;
  }
  cout << ans << endl;
  return 0;
}
