#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
string int_to_string(const int& port) {
  stringstream ss;
  ss << port;
  return ss.str();
}
int main() {
  string s;
  cin >> s;
  int digit[10] = {0};
  for (int i = 0; i < s.size(); i++) {
    digit[s[i] - '0']++;
  }
  digit[1]--;
  digit[6]--;
  digit[8]--;
  digit[9]--;
  int so[] = {1, 6, 8, 9};
  vector<string> permu;
  do {
    string tmp = "";
    tmp += int_to_string(so[0]);
    tmp += int_to_string(so[1]);
    tmp += int_to_string(so[2]);
    tmp += int_to_string(so[3]);
    permu.push_back(tmp);
  } while (next_permutation(so, so + 4));
  int muon = 0;
  for (int i = 1; i <= 9; i++) {
    for (int j = 0; j < digit[i]; j++) {
      muon = (muon * 10 + i) % 7;
      cout << i;
    }
  }
  for (int i = 0; i < permu.size(); i++) {
    string tmp = int_to_string(muon) + permu[i];
    int tmp1 = atoi(tmp.c_str());
    if (tmp1 % 7 == 0) {
      cout << permu[i];
      break;
    }
  }
  for (int i = 0; i < digit[0]; i++) {
    cout << 0;
  }
  return 0;
}
