#include <bits/stdc++.h>
using namespace std;
int main() {
  bool flag = false;
  vector<int> lh, rh;
  int minsc = 0;
  int x;
  int lhs[5], rhs[5];
  string time;
  cin >> time;
  for (int i = 0; i < time.length(); i++) {
    if (time[i] == ':') {
      flag = true;
      continue;
    }
    if (flag) {
      if (time[i] >= 48 && time[i] <= 57)
        rh.push_back(time[i] - 48);
      else
        rh.push_back(time[i] - 55);
    } else {
      if (time[i] >= 48 && time[i] <= 57)
        lh.push_back(time[i] - 48);
      else
        lh.push_back(time[i] - 55);
    }
  }
  for (int i = 0; i < 5; i++) {
    lhs[i] = rhs[i] = 0;
  }
  for (int i = lh.size() - 1, j = 0; i >= 0; i--, j++) {
    lhs[j] = lh[i];
  }
  for (int i = rh.size() - 1, j = 0; i >= 0; i--, j++) {
    rhs[j] = rh[i];
  }
  for (int i = 0; i < 5; i++) {
    if (minsc < lhs[i] && lhs[i] != 0) minsc = lhs[i];
    if (minsc < rhs[i] && rhs[i] != 0) minsc = rhs[i];
  }
  flag = false;
  for (int i = 1; i < 5; i++) {
    if (lhs[i] != 0 || rhs[i] != 0) {
      flag = true;
      break;
    }
  }
  if (!flag) {
    if (lhs[0] >= 0 && lhs[0] <= 23) {
      cout << "-1";
      return 0;
    }
  }
  flag = true;
  x = minsc + 1;
  while (flag) {
    int s1, s2;
    s1 = lhs[4] * x * x * x * x + lhs[3] * x * x * x + lhs[2] * x * x +
         lhs[1] * x + lhs[0];
    s2 = rhs[4] * x * x * x * x + rhs[3] * x * x * x + rhs[2] * x * x +
         rhs[1] * x + rhs[0];
    if (s1 >= 24 || s2 >= 60)
      flag = false;
    else {
      cout << x << " ";
      x++;
    }
  }
  if (x == minsc + 1) cout << "0";
}
