#include <bits/stdc++.h>
using namespace std;
long long x, ans[1000005];
string s;
char n[1000005], m;
vector<pair<long long, long long> > bugs;
vector<pair<long long, pair<long long, long long> > > stu;
set<pair<long long, long long> > mys;
int main() {
  cin >> s;
  int a = 0, b = 0, c = 0, d = 0, pos = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1' && !a)
      a = 1;
    else if (s[i] == '6' && !b)
      b = 1;
    else if (s[i] == '8' && !c)
      c = 1;
    else if (s[i] == '9' && !d)
      d = 1;
    else
      n[pos++] = s[i];
  }
  int res = 0;
  for (int i = 0; i < pos; i++) {
    res = (res * 10 + (n[i] - '0')) % 7;
  }
  if (res == 0) s = "1869";
  if (res == 5) s = "8961";
  if (res == 3) s = "1689";
  if (res == 1) s = "6198";
  if (res == 6) s = "8691";
  if (res == 4) s = "8916";
  if (res == 2) s = "8196";
  int cnt = 0;
  int i;
  for (i = 0; i < pos && n[i] == '0'; i++) cnt++;
  for (; i < pos; i++) cout << n[i];
  cout << s;
  for (int i = 0; i < cnt; i++) cout << '0';
}
