#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
char r1[6], r2[6];
int pwr(int n, int b) {
  long long res = 1;
  for (int i = 1; i <= b; ++i) res *= n;
  return res;
}
int main() {
  string a, b;
  scanf(" %[^:]:%s", r1, r2);
  a = r1, b = r2;
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  vector<int> res;
  for (int i = 60; i >= 2; --i) {
    long long h = 0, m = 0;
    for (int j = 0; j < (int)a.size(); ++j) {
      int f = 0;
      if (a[j] >= 'A' && a[j] <= 'Z')
        f = (a[j] - 'A') + 10;
      else
        f = (a[j] - '0');
      if (f >= i) {
        h = 100, m = 100;
        goto next;
      }
      h += 1ll * pwr(i, j) * f;
    }
    for (int j = 0; j < (int)b.size(); ++j) {
      int f = 0;
      if (b[j] >= 'A' && b[j] <= 'Z')
        f = (b[j] - 'A') + 10;
      else
        f = (b[j] - '0');
      if (f >= i) {
        h = 100, m = 100;
        goto next;
      }
      m += 1ll * pwr(i, j) * f;
    }
  next:
    if (h > 23 || m > 59) continue;
    if (i == 60) {
      puts("-1");
      return 0;
    }
    res.push_back(i);
  }
  if (!res.size())
    puts("0");
  else {
    for (int i = res.size() - 1; i >= 0; --i) printf("%d ", res[i]);
  }
  return 0;
}
