#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  getline(cin, a, ':');
  getline(cin, b);
  int max1 = -1;
  for (int i = 0; i < a.length(); i++)
    if (a[i] >= 'A') {
      if (a[i] - 'A' + 10 > max1) max1 = a[i] - 'A' + 10;
    } else if (a[i] - '0' > max1)
      max1 = a[i] - '0';
  int r1 = 0;
  while (r1 < a.length() && a[r1] == '0') r1++;
  int r2 = 0;
  while (r2 < b.length() && b[r2] == '0') r2++;
  if (((r1 == a.length() - 1 && a[r1] <= 'N') || r1 > a.length() - 1) &&
      r2 >= b.length() - 1) {
    cout << "-1";
    return 0;
  } else if (r1 >= a.length() - 1 && r2 >= b.length() - 1) {
    cout << '0';
    return 0;
  }
  for (int i = 0; i < b.length(); i++)
    if (b[i] >= 'A') {
      if (b[i] - 'A' + 10 > max1) max1 = b[i] - 'A' + 10;
    } else if (b[i] - '0' > max1)
      max1 = b[i] - '0';
  vector<int> c;
  for (int i = max1 + 1; i <= 1000; i++) {
    int p = 1;
    int s = 0;
    for (int j = a.length() - 1; j >= 0; j--) {
      if (a[j] >= 'A')
        s += (a[j] - 'A' + 10) * p;
      else
        s += (a[j] - '0') * p;
      p *= i;
    }
    p = 1;
    int s1 = 0;
    for (int j = b.length() - 1; j >= 0; j--) {
      if (b[j] >= 'A')
        s1 += (b[j] - 'A' + 10) * p;
      else
        s1 += (b[j] - '0') * p;
      p *= i;
    }
    if (s < 24 && s >= 0 && s1 < 60 && s1 >= 0)
      c.push_back(i);
    else
      break;
  }
  if (c.size() == 0)
    cout << '0';
  else
    for (int i = 0; i < c.size(); i++) cout << c[i] << ' ';
  return 0;
}
