#include <bits/stdc++.h>
using namespace std;
long n, m;
map<int, int> rt;
string t;
long ry = 0;
string p[] = {"1869", "6198", "1896", "9186", "9168", "6189", "8691"};
void df(int k) {
  for (int i = 1; i <= rt[k]; ++i) {
    ry = (ry * 10 + k) % 7;
    cout << k;
  }
}
int main() {
  cin >> t;
  for (int k = 0; k < t.size(); ++k) {
    rt[t[k] - '0']++;
  }
  --rt[1];
  --rt[6];
  --rt[8];
  --rt[9];
  for (int k = 1; k <= 9; ++k) df(k);
  cout << p[ry];
  df(0);
  return 0;
}
