#include <bits/stdc++.h>
using namespace std;
const int O = 1000;
struct node {
  int x, y, z;
} pre[1005][2005][2];
queue<node> q;
int a, biggest[1005][2005][2];
bool getthrough[1005][2005][2];
inline string solve() {
  getthrough[0][O][0] = 1;
  biggest[0][O][0] = -1;
  q.push({0, O, 0});
  while (!q.empty()) {
    int i = q.front().x, j = q.front().y, tp = q.front().z;
    if (i == 0 && j == O && tp == 1) {
      string re = "";
      node tmp;
      while (~biggest[i][j][tp]) {
        if (!re.empty() || biggest[i][j][tp]) re += biggest[i][j][tp] + '0';
        tmp = pre[i][j][tp];
        i = tmp.x, j = tmp.y, tp = tmp.z;
      }
      return re;
    }
    for (int k = 0; k < 10; ++k) {
      int x = (i + k * a) / 10;
      int y = (i + k * a) % 10 * a + j - k;
      int z = (tp || k);
      if (y >= 0 && y <= 2000 && !getthrough[x][y][z])
        getthrough[x][y][z] = 1, biggest[x][y][z] = k, pre[x][y][z] = q.front(),
        q.push({x, y, z});
    }
    q.pop();
  }
  return "-1";
}
int main() {
  scanf("%d", &a);
  string ret = solve();
  cout << ret << endl;
}
