#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > mapa;
void init() {
  vector<int> p;
  p.push_back(1);
  p.push_back(6);
  p.push_back(8);
  p.push_back(9);
  do {
    int curr = 1000 * p[0] + 100 * p[1] + 10 * p[2] + p[3];
    mapa[curr % 7] = p;
  } while (next_permutation(p.begin(), p.end()));
}
int main() {
  init();
  string s = "1689";
  bool done[12];
  memset(done, 0, sizeof(done));
  string in;
  int md = 0;
  cin >> in;
  vector<char> zr;
  for (int i = 0; i < in.size(); i++) {
    if (in[i] == '0') {
      zr.push_back(in[i]);
      continue;
    }
    if (s.find(in[i]) == string::npos) {
      cout << in[i];
      md = 10 * md + (in[i] - '0');
      md = md % 7;
    } else {
      if (done[in[i] - '0']) {
        cout << in[i];
        md = 10 * md + (in[i] - '0');
        md = md % 7;
      } else {
        done[in[i] - '0'] = true;
      }
    }
  }
  for (int tp = 0; tp < 7; tp++) {
    int ms = 10000 * md + tp;
    if (ms % 7 == 0) {
      vector<int> ans = mapa[tp];
      for (int i = 0; i < ans.size(); i++) cout << ans[i];
      break;
    }
  }
  for (int i = 0; i < zr.size(); i++) cout << zr[i];
  cout << endl;
  return 0;
}
