#include <bits/stdc++.h>
using namespace std;
int mod(string num, int a) {
  int res = 0;
  for (int i = 0; i < num.length(); i++)
    res = (res * 10 + (int)num[i] - '0') % a;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int c0 = 0;
  string st = "";
  map<char, int> m;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != '1' && s[i] != '6' && s[i] != '8' && s[i] != '9' &&
        s[i] != '0') {
      st += s[i];
    }
    if (s[i] == '1') {
      m['1']++;
    }
    if (s[i] == '6') {
      m['6']++;
    }
    if (s[i] == '8') {
      m['8']++;
    }
    if (s[i] == '9') {
      m['9']++;
    }
    if (s[i] == '1' && m[s[i]] > 1) {
      st += s[i];
    }
    if (s[i] == '6' && m[s[i]] > 1) {
      st += s[i];
    }
    if (s[i] == '8' && m[s[i]] > 1) {
      st += s[i];
    }
    if (s[i] == '9' && m[s[i]] > 1) {
      st += s[i];
    }
    if (s[i] == '0') {
      c0++;
    }
  }
  int y = 0;
  if (st.size() > 0) y = mod(st, 7);
  if (y == 0) {
    st += "1869";
  } else if (y == 1) {
    st += "6891";
  } else if (y == 2) {
    st += "8196";
  } else if (y == 3) {
    st += "1689";
  } else if (y == 4) {
    st += "1986";
  } else if (y == 5) {
    st += "1968";
  } else if (y == 6) {
    st += "8691";
  }
  while (c0--) {
    st += "0";
  }
  cout << st;
}
