#include <bits/stdc++.h>
using namespace std;
char str[50];
int p, j, k;
int a[11];
int b[11];
bool check(int x) {
  int suma = 0, sumb = 0;
  for (int i = 0; i < j; i++) {
    if (a[i] >= x) {
      return false;
    }
  }
  for (int i = 0; i < k; i++) {
    if (b[i] >= x) {
      return false;
    }
  }
  for (int i = 0; i < j; i++) {
    int tmp = 1;
    for (int n = i + 1; n < j; n++) {
      tmp *= x;
    }
    suma += a[i] * tmp;
    if (suma >= 24) return false;
  }
  for (int i = 0; i < k; i++) {
    int tmp = 1;
    for (int n = i + 1; n < k; n++) {
      tmp *= x;
    }
    sumb += b[i] * tmp;
    if (sumb >= 60) return false;
  }
  return true;
}
int main() {
  int ok = 0, flag = 0;
  cin >> str;
  int len = strlen(str);
  for (int i = 0; i < len; i++) {
    if (str[i] == ':') {
      p = i;
    }
  }
  for (int i = 0; i < p; i++) {
    while (str[i] == '0' && !flag) i++;
    if (i == p) break;
    flag = 1;
    if (str[i] >= 'A' && str[i] <= 'Z')
      a[j] = str[i] - 'A' + 10;
    else
      a[j] = str[i] - '0';
    j++;
  }
  flag = 0;
  for (int i = p + 1; i < len; i++) {
    while (str[i] == '0' && !flag) i++;
    if (i == p) break;
    flag = 1;
    if (str[i] >= 'A' && str[i] <= 'Z')
      b[k] = str[i] - 'A' + 10;
    else
      b[k] = str[i] - '0';
    k++;
  }
  if ((j == 0 || (j == 1 && a[0] < 24)) && (k == 0 || k == 1)) {
    cout << -1 << endl;
    ok = 1;
  } else {
    for (int i = 2; i <= 60; i++) {
      if (check(i)) {
        ok = 1;
        cout << i << ' ';
      }
    }
    if (ok) cout << endl;
  }
  if (!ok) cout << 0 << endl;
}
