#include <bits/stdc++.h>
using namespace std;
const int N = 101;
char s[N], a[N], b[N];
map<pair<long, long>, bool> f;
vector<int> ans;
long long get(char s[], int base) {
  long long res = 0;
  for (int i = 0; s[i]; i++) {
    int t;
    if (s[i] >= '0' && s[i] <= '9')
      t = s[i] - '0';
    else
      t = s[i] - 'A' + 10;
    if (t >= base) return 61;
    res = res * base + t;
  }
  return res;
}
int main() {
  scanf("%s", s);
  for (int i = 0; s[i]; i++) {
    if (s[i] == ':') break;
    a[i] = s[i];
  }
  for (int i = 0, j = 0, p = 0; s[i]; i++) {
    if (j) b[p++] = s[i];
    if (s[i] == ':') j = 1;
  }
  for (int i = (2); i < (101); i++) {
    long long x = get(a, i), y = get(b, i);
    if (x < 24 && y < 60) {
      if (f.count(make_pair(x, y))) return 0 * puts("-1");
      f[make_pair(x, y)] = 1;
      ans.push_back(i);
    }
  }
  for (int i = (0); i < ((int)ans.size()); i++) printf("%d ", ans[i]);
  if ((int)ans.size() == 0) puts("0");
  return 0;
}
