#include <bits/stdc++.h>
using namespace std;
int kkaass = 1;
string str;
int nisi[10];
vector<int> vec, zero;
string final;
int main() {
  int i, j, k;
  while (cin >> str) {
    final.clear();
    memset(nisi, 0, sizeof(nisi));
    vec.clear();
    zero.clear();
    for (i = 0; i < ((int)str.size()); i++) {
      int d = str[i] - '0';
      if (d == 1 || d == 6 || d == 8 || d == 9) {
        if (nisi[d])
          vec.push_back(d);
        else
          nisi[d] = 1;
      } else if (d == 0)
        zero.push_back(d);
      else
        vec.push_back(d);
    }
    int obo = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
      obo = (obo * 10 + vec[i]) % 7;
      final += (char)(vec[i] + '0');
    }
    int done = 0;
    string mja = "1689";
    do {
      string fin = ((char)(obo + '0')) + mja;
      stringstream ss;
      ss << fin;
      int val;
      ss >> val;
      if (val % 7 == 0) {
        done = 1;
        break;
      }
    } while (next_permutation(mja.begin(), mja.end()));
    if (done) {
      final += mja;
      for (int i = 0; i < (int)zero.size(); i++) final += "0";
      cout << final << endl;
    } else
      cout << 0 << endl;
  }
  return 0;
}
