#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
char str[30];
int arr[100];
int main() {
  cin >> str;
  int l = strlen(str);
  int p = strchr(str, ':') - str;
  int K = 0;
  int flag = 0;
  for (int i = 1; i <= 60; i++) {
    long long a = 0, b = 0;
    bool ok = 1;
    for (int j = 0; j < p; j++) {
      int k = str[j] - '0';
      if (str[j] >= 'A' && str[j] <= 'Z') k = str[j] - 'A' + 10;
      if (k >= i) {
        ok = 0;
        break;
      }
      a *= i;
      a += k;
    }
    if (!ok) continue;
    for (int j = p + 1; j < l; j++) {
      int k = str[j] - '0';
      if (str[j] >= 'A' && str[j] <= 'Z') k = str[j] - 'A' + 10;
      if (k >= i) {
        ok = 0;
        break;
      }
      b *= i;
      b += k;
    }
    if (!ok) continue;
    if (a > 23LL || b > 59LL) continue;
    arr[K++] = i;
    if (i == 60) flag = 1;
  }
  if (!K)
    puts("0");
  else {
    if (flag)
      puts("-1");
    else {
      for (int i = 0; i < K; i++) cout << arr[i] << ' ';
    }
  }
  return 0;
}
