#include <bits/stdc++.h>
using namespace std;
long long k[4] = {1, 6, 8, 9}, sum, x = 1, sol, z, a[10], j;
vector<char> v;
string s;
int main() {
  cin >> s;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '0') {
      z++;
      continue;
    } else if ((s[i] == '1' && a[s[i] - '0'] == 0) ||
               (s[i] == '6' && a[s[i] - '0'] == 0) ||
               (s[i] == '8' && a[s[i] - '0'] == 0) ||
               (s[i] == '9' && a[s[i] - '0'] == 0)) {
      a[s[i] - '0'] = 1;
      continue;
    }
    sum += (x * (s[i] - '0')) % 7;
    sum %= 7;
    x *= 10;
    x %= 7;
    v.push_back(s[i]);
  }
  while (next_permutation(k, k + 4)) {
    if ((k[0] * x * 1000 + k[1] * x * 100 + k[2] * x * 10 + k[3] * x + sum) %
            7 ==
        0) {
      cout << k[0] << k[1] << k[2] << k[3];
      break;
    }
  }
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) cout << v[i];
  for (int i = 0; i < z; i++) cout << 0;
  return 0;
}
