#include <bits/stdc++.h>
using namespace std;
int zero;
bool a1, a6, a8, a9;
int ost;
int main(void) {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1' && !a1)
      a1 = true;
    else if (s[i] == '6' && !a6)
      a6 = true;
    else if (s[i] == '8' && !a8)
      a8 = true;
    else if (s[i] == '9' && !a9)
      a9 = true;
    else if (s[i] == '0')
      zero++;
    else {
      cout << s[i];
      ost *= 10;
      ost += (int)s[i] - '0';
      ost = ost % 7;
    }
  }
  switch (ost) {
    case 0:
      cout << 1869;
      break;
    case 1:
      cout << 6891;
      break;
    case 2:
      cout << 1896;
      break;
    case 3:
      cout << 1689;
      break;
    case 4:
      cout << 1986;
      break;
    case 5:
      cout << 1968;
      break;
    case 6:
      cout << 1698;
      break;
  }
  for (int i = 0; i < zero; i++) cout << 0;
  cin >> s;
  return 0;
}
