#include <bits/stdc++.h>
using namespace std;
int arr[] = {1869, 6198, 1896, 1689, 1986, 8961, 1698};
int pos[4];
int main() {
  string num;
  cin >> num;
  int rem = 0;
  pos[0] = pos[1] = pos[2] = pos[3] = -1;
  int calc = 0;
  int first = 1;
  for (int i = 0; i < num.length(); ++i) {
    int got = 0;
    if (num[i] == '1' && pos[0] == -1) {
      got = 1;
      pos[0] = i;
    }
    if (num[i] == '6' && pos[1] == -1) {
      got = 1;
      pos[1] = i;
    }
    if (num[i] == '8' && pos[2] == -1) {
      got = 1;
      pos[2] = i;
    }
    if (num[i] == '9' && pos[3] == -1) {
      got = 1;
      pos[3] = i;
    }
    if (!got) {
      if (first && num[i] == '0') {
        ++calc;
      } else {
        rem = (rem * 10 + (num[i] - '0')) % 7;
        cout << num[i];
      }
    }
  }
  cout << arr[rem];
  while (calc--) cout << "0";
  cout << endl;
  return 0;
}
