#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using lli = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
int main() {
  string temp = "1689";
  string str;
  cin >> str;
  map<int, int> m;
  for (int i = 0; i < str.length(); i++) {
    m[str[i] - '0']++;
  }
  int rem = 0;
  for (int i = 1; i <= 9; i++) {
    if (i == 1 || i == 6 || i == 8 || i == 9) {
      for (int j = 0; j < m[i] - 1; j++) {
        rem = rem * 10 + i;
        rem %= 7;
      }
    } else {
      for (int j = 0; j < m[i]; j++) {
        rem = rem * 10 + i;
        rem %= 7;
      }
    }
  }
  map<int, string> hash;
  do {
    int a = stoi(temp);
    hash[a % 7] = temp;
  } while (next_permutation(temp.begin(), temp.end()));
  for (int i = 1; i <= 9; i++) {
    if (i == 1 || i == 6 || i == 8 || i == 9) {
      for (int j = 0; j < m[i] - 1; j++) cout << i;
    } else {
      for (int j = 0; j < m[i]; j++) cout << i;
    }
  }
  rem = rem * 10000;
  rem %= 7;
  rem = (7 - rem) % 7;
  cout << hash[rem];
  for (int i = 0; i < m[0]; i++) {
    cout << 0;
  }
  cout << "\n";
  return 0;
}
