#include <bits/stdc++.h>
using namespace std;
long long Pwr(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b % 2) {
      res = res * a % m;
    }
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
int main() {
  long long r = 0, six = 0, one = 0, eight = 0, nine = 0, ans = 0, i, zero = 0;
  string s, s2 = "";
  cin >> s;
  long long n = s.length();
  for (i = 0; i < n; i++) {
    if (s[i] == '1' && one == 0) {
      one++;
      continue;
    } else if (s[i] == '6' && six == 0) {
      six++;
      continue;
    } else if (s[i] == '8' && eight == 0) {
      eight++;
      continue;
    } else if (s[i] == '9' && nine == 0) {
      nine++;
      continue;
    } else if (s[i] == '0') {
      zero++;
    } else {
      s2 += s[i];
    }
  }
  if (!s2.empty()) {
    for (i = s.length() - 1 - zero; i >= 4; i--) {
      ans = (ans % 7 + (Pwr(10, i, 7) * (s2[r] - '0') % 7) % 7) % 7;
      r++;
    }
  }
  if (ans == 0) {
    s2 += "1869";
  } else if (ans == 6) {
    s2 += "1968";
  } else if (ans == 5) {
    s2 += "1689";
  } else if (ans == 4) {
    s2 += "6891";
  } else if (ans == 3) {
    s2 += "8691";
  } else if (ans == 2) {
    s2 += "9168";
  } else if (ans == 1) {
    s2 += "8196";
  }
  for (i = 0; i < zero; i++) {
    s2 += "0";
  }
  cout << s2;
  return 0;
}
