#include <bits/stdc++.h>
using namespace std;
string st;
int remt = 1;
int rem = 0;
int arr[24];
int main() {
  cin >> st;
  for (int i = 0; i < st.size(); i++) {
    if (st[i] == '1') {
      st.erase(st.begin() + i, st.begin() + i + 1);
      break;
    }
  }
  for (int i = 0; i < st.size(); i++) {
    if (st[i] == '6') {
      st.erase(st.begin() + i, st.begin() + i + 1);
      break;
    }
  }
  for (int i = 0; i < st.size(); i++) {
    if (st[i] == '8') {
      st.erase(st.begin() + i, st.begin() + i + 1);
      break;
    }
  }
  for (int i = 0; i < st.size(); i++) {
    if (st[i] == '9') {
      st.erase(st.begin() + i, st.begin() + i + 1);
      break;
    }
  }
  for (int i = 0; i < st.size(); i++) {
    rem = rem * 10 + (st[i] - '0');
    rem = (rem + 7) % 7;
  }
  for (int i = 0; i < st.size(); i++) {
    remt = remt * 10;
    remt = remt % 7;
  }
  arr[0] = 1986;
  arr[1] = 1968;
  arr[2] = 1698;
  arr[3] = 1689;
  arr[4] = 1896;
  arr[5] = 1869;
  arr[6] = 6198;
  arr[7] = 6189;
  arr[8] = 6891;
  arr[9] = 6819;
  arr[10] = 6981;
  arr[11] = 6918;
  arr[12] = 9168;
  arr[13] = 9186;
  arr[14] = 9618;
  arr[15] = 9681;
  arr[16] = 9861;
  arr[17] = 9816;
  arr[18] = 8196;
  arr[19] = 8169;
  arr[20] = 8619;
  arr[21] = 8691;
  arr[22] = 8961;
  arr[23] = 8916;
  for (int i = 0; i < 24; i++) {
    if ((arr[i] * remt + rem) % 7 == 0) {
      cout << arr[i];
      break;
    }
  }
  for (int i = 0; i < st.size(); i++) {
    cout << st[i];
  }
  return 0;
}
