#include <bits/stdc++.h>
using namespace std;
int main() {
  string luck[7] = {"1869", "1968", "1689", "6198", "1698", "1986", "1896"};
  string str;
  cin >> str;
  int ans = 0;
  bool vis[10];
  int zero = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == '0')
      zero++;
    else if (!vis[1] && str[i] == '1')
      vis[1] = true;
    else if (!vis[6] && str[i] == '6')
      vis[6] = true;
    else if (!vis[8] && str[i] == '8')
      vis[8] = true;
    else if (!vis[9] && str[i] == '9')
      vis[9] = true;
    else {
      printf("%c", str[i]);
      ans = ans * 10 + str[i] - '0';
      ans %= 7;
    }
  }
  ans = ans * 10000;
  ans %= 7;
  cout << luck[(7 - ans) % 7];
  while (zero--) printf("0");
  printf("\n");
  return 0;
}
