#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  string last = "1869";
  for (int i = 0; i < last.size(); i++) {
    s.erase(find(s.begin(), s.end(), last[i]));
  }
  if (count(s.begin(), s.end(), '0') == s.size()) {
    cout << last + s << endl;
    return 0;
  }
  sort(s.rbegin(), s.rend());
  do {
    string str = s + last;
    long long int num = 0;
    for (int i = 0; i < str.size(); i++) {
      num = num * 10 + (str[i] - '0');
      num %= 7;
    }
    if (num == 0) {
      cout << str << endl;
      return 0;
    }
  } while (next_permutation(last.begin(), last.end()));
  cout << 0 << endl;
}
