#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  string s, s1 = "", s2 = "";
  cin >> s;
  int x1 = s.find('1');
  int x8 = s.find('8');
  int x6 = s.find('6');
  int x9 = s.find('9');
  int zc = 0;
  for (long long i = 0; i < s.size(); i++) {
    if (i != x1 && i != x8 && i != x6 && i != x9) {
      if (s[i] != '0')
        s1 += s[i];
      else
        s2 += '0';
    }
  }
  int x = 0;
  if (s1 != "") x = (s1[0] - '0');
  int carry = x;
  for (long long i = 1; i < s1.size(); i++) {
    x = x * 10 + (s1[i] - '0');
    carry = x % 7;
    x = carry;
  }
  string ans = "";
  carry %= 7;
  if (carry == 1) {
    ans += s1 + string("6891") + s2;
  } else if (carry == 2) {
    ans += s1 + string("8196") + s2;
  } else if (carry == 3) {
    ans += s1 + string("6918") + s2;
  } else if (carry == 4) {
    ans += s1 + string("1986") + s2;
  } else if (carry == 5) {
    ans += s1 + string("6819") + s2;
  } else if (carry == 6) {
    ans += s1 + string("1698") + s2;
  } else if (carry == 0) {
    ans += s1 + string("1869") + s2;
  }
  cout << ans << endl;
  return 0;
}
