#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string second, a = "1968";
  string rem[10];
  cin >> second;
  int zero = 0;
  bool one = 0, six = 0, eight = 0, nine = 0;
  string alt = "";
  for (int i = 0; i < second.size(); i++) {
    if (second[i] == '0') zero++;
    if (second[i] == '1' && one) alt += second[i];
    if (second[i] == '6' && six) alt += second[i];
    if (second[i] == '8' && eight) alt += second[i];
    if (second[i] == '9' && nine) alt += second[i];
    if (second[i] == '1')
      one = 1;
    else if (second[i] == '6')
      six = 1;
    else if (second[i] == '8')
      eight = 1;
    else if (second[i] == '9')
      nine = 1;
    else if (second[i] != '0')
      alt += second[i];
  }
  int t = 1, mo = 0;
  for (int i = 0; i < zero; i++) {
    t = (t * 10) % 7;
  }
  int ft = t;
  do {
    int m = 0;
    t = ft;
    for (int i = 4 - 1; i >= 0; i--) {
      m = (m + t * (a[i] - '0')) % 7;
      t = (t * 10) % 7;
    }
    rem[m] = a;
  } while (next_permutation(a.begin(), a.end()));
  for (int i = alt.size() - 1; i >= 0; i--) {
    mo = (mo + (alt[i] - '0') * t) % 7;
    t = (t * 10) % 7;
  }
  rem[7] = rem[0];
  cout << alt << rem[7 - mo];
  for (int i = 0; i < zero; i++) cout << 0;
  return 0;
}
