#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
  string str, output("");
  cin >> str;
  vector<bool> array(10, false);
  int nzero = 0, val = 0, rem = 0;
  for (int i = 0; i < str.size(); ++i) {
    val = str[i] - '0';
    switch (val) {
      case 1:
      case 6:
      case 8:
      case 9:
        if (array[val]) {
          rem = (rem * 10 + val) % 7;
          output.push_back(str[i]);
        } else {
          array[val] = true;
        }
        break;
      case 0:
        nzero += 1;
        break;
      default:
        rem = (rem * 10 + val) % 7;
        output.push_back(str[i]);
        break;
    }
  }
  rem = (rem * 10000) % 7;
  switch (rem) {
    case 0:
      output.append("1869");
      break;
    case 1:
      output.append("1896");
      break;
    case 2:
      output.append("1986");
      break;
    case 3:
      output.append("1698");
      break;
    case 4:
      output.append("6198");
      break;
    case 5:
      output.append("1689");
      break;
    case 6:
      output.append("1968");
      break;
  }
  while (nzero--) output.push_back('0');
  cout << output << endl;
  return 0;
}
