#include <bits/stdc++.h>
using namespace std;
int modu[1000000];
int main() {
  int mul = 1;
  for (int i = 0; i < 1000000; i++) {
    modu[i] = mul;
    mul = (mul * 10) % 7;
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a[4] = {1, 6, 8, 9};
  bool b[4];
  int c[7];
  int m;
  memset(b, 0, sizeof b);
  for (int i = 0; i < 4; i++) {
    b[i] = true;
    m = a[i];
    for (int j = 0; j < 4; j++) {
      if (!b[j]) {
        b[j] = true;
        m = m * 10 + a[j];
        for (int k = 0; k < 4; k++) {
          if (!b[k]) {
            b[k] = true;
            m = m * 10 + a[k];
            for (int l = 0; l < 4; l++) {
              if (!b[l]) {
                m = m * 10 + a[l];
                c[m % 7] = m;
                m = (m - a[l]) / 10;
              }
            }
            b[k] = false;
            m = (m - a[k]) / 10;
          }
        }
        b[j] = false;
        m = (m - a[j]) / 10;
      }
    }
    b[i] = false;
  }
  string s;
  cin >> s;
  int d[10];
  for (int i = 0; i < 10; i++) d[i] = 0;
  string ans;
  for (int i = 0; i < s.length(); i++) {
    d[s[i] - '0']++;
  }
  d[1]--;
  d[6]--;
  d[8]--;
  d[9]--;
  int moduans = 0;
  for (char i = 1; i <= 9; i++)
    for (int j = 0; j < d[i]; j++) ans += i + '0';
  for (int i = ans.length() - 1; i >= 0; i--) {
    moduans = (moduans + (int)(ans[i] - '0') * modu[ans.length() - 1 - i]) % 7;
  }
  moduans = (moduans * modu[4]) % 7;
  stringstream ss;
  ss << c[(7 - moduans) % 7];
  ans = ans + ss.str();
  for (int i = 0; i < d[0]; i++) ans += '0';
  cout << ans << endl;
  return 0;
}
