#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int n, m;
int cnt[13];
int cn[13]; //tmpcnt
int rest[13]; //rest of use
int usenum; //use number
int S; // bit
typedef pair<int, int> P;
typedef pair<P, int> PP;
set<PP> memo;
bool dfs(int idx){
  if(memo.count(make_pair(make_pair(idx, usenum), cn[12]))) return false;
  memo.insert(make_pair(make_pair(idx, usenum), cn[12]));
  if(usenum >= n) return true;
  if(idx > 11) return false;
  if(S & (1 << usenum)){
    //111
    for(int i = 0; i <= 3; i++){
      if(cn[idx] < i) break;
      if(rest[idx] < 3 - i || cn[12] < 3 - i) continue;
      usenum ++;
      cn[idx] -= i;
      rest[idx] -= 3 - i;
      cn[12] -= 3 - i;
      if(dfs(idx)) return true;
      usenum --;
      cn[idx] += i;
      rest[idx] += 3 - i;
      cn[12] += 3 - i;
    }
    if(cn[idx] > 0) return false;
    return dfs(idx + 1);
  }else{
    //123
    if(idx + 2 > 11) return false;
    for(int S2 = 0; S2 < 1<<3; S2++){
      bool ok = true;
      if(__builtin_popcount(S2) > cn[12]) ok = false;
      for(int i = 0; i <= 2; i++){
        if(S2 & (1 << i)){
          if(rest[idx+i] == 0) ok = false;
        }else{
          // not use
          if(cn[idx+i] == 0) ok = false;
        }
      }
      if(!ok) continue;
      usenum ++;
      for(int i = 0; i <= 2; i++){
        if(S2 & (1 << i)){
          rest[idx+i] -= 1;
          cn[12] -= 1;
        }else{
          // not use
          cn[idx+i] -= 1;
        }
      }
      assert(cn[12] >= 0);
      if(dfs(idx)) return true;
      usenum --;
      for(int i = 0; i <= 2; i++){
        if(S2 & (1 << i)){
          rest[idx+i] += 1;
          cn[12] += 1;
        }else{
          // not use
          cn[idx+i] += 1;
        }
      }
    }
    if(cn[idx] > 0) return false;
    return dfs(idx + 1);
  }
  return false;
}
bool ok(){
  /*
  for(int i = 0; i < 13; i++){
    printf("%d:%d\n", i, cnt[i]);
  }
  */
  for(int two = 0; two < 12; two++){
    REP(i, 13)cn[i] = cnt[i];
    REP(i, 12)rest[i] = 4 - cnt[i];
    if(cn[two] + cn[12] >= 2){
      int r = min(cn[two], 2);
      if(rest[two] >= 2 - r){
        cn[two] -= r;
        cn[12] -= 2 - r;
        rest[two] -= 2 - r;
      }
    }
    else continue;
    /*
    for(int i = 0; i < 13; i++){
      printf("%d:%d\n", i, cn[i]);
    }
    */
    REP(tS, 1<<n){
      usenum = 0;
      S = tS;
      memo.clear();
      if(dfs(0)) return true;
    }
  }
  return false;
}

int main(){
  while(cin>>n){
    memset(cnt, 0, sizeof(cnt));
    m = 3 * n + 2;
    REP(i, m - 1){
      string s; cin>>s;
      if(s == "*"){
        cnt[12]++;
        continue;
      }
      stringstream ss(s);
      int n;
      ss>>n;
      cnt[n-1]++;
    }
    int asss = 0;
    REP(i, 12){
      assert(cnt[i] <= 4);
      if(cnt[i] == 4) continue;
      cnt[i]++;
      if(ok()) {
        cout<<i+1<<endl;
        asss++;
      }
      cnt[i]--;
    }
    if(asss == 0) cout<<-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1248