#include <bits/stdc++.h>
using namespace std;
string dp[7] = {"1869", "6198", "1896", "9186", "9168", "6189", "8691"};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> arr(10, 0);
  for (int i = 0; i < n; i++) {
    arr[s[i] - '0']++;
  }
  arr[1]--;
  arr[8]--;
  arr[6]--;
  arr[9]--;
  int rem = 0;
  for (int i = 1; i <= 9; i++) {
    while (arr[i] > 0) {
      cout << i;
      rem *= 10;
      rem += i;
      rem %= 7;
      arr[i]--;
    }
  }
  cout << dp[rem];
  while (arr[0] > 0) {
    cout << "0";
    arr[0]--;
  }
  cout << '\n';
}
