#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<iomanip>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

string table[]={"qwertasdfgzxcvb","yuiophjklnm"};


int main(){

	while(true){
		int n,q;
		vector<int> date;
		
		cin >> n >> q;

		
		if(n==0&&q==0) break;


		for(int i=0;i<=100;i++){
			date.push_back(0);
		}

		for(int i=0;i<n;i++){
			int m,d;
			cin >> m;
			for(int k=0;k<m;k++){
				cin >> d;
				date[d]++;				
			}
		}

		int decide=0,day=0;

		for(int i=0;i<100;i++){
			if(date[i]>decide && date[i] >= q){
				decide=date[i];	
				day=i;
			}
		}

		cout << day << endl;
	}

}
#include <iostream>
#include <map>

using namespace std;

#define MN 101

int n;
int ks[MN];
string raw;

map<char, int> kmap;
map<int, char> rkmap;

void init_() {
    for (char i = 'a'; i <= 'z'; i++) {
        kmap[i] = i - 'a';
        rkmap[i - 'a'] = i;
    }
    for (char i = 'A'; i <= 'Z'; i++) {
        kmap[i] = i - 'A' + 26;
        rkmap[i - 'A' + 26] = i;
    }
}

bool init() {
    cin >> n;
    if (n == 0) return false;
    for (int i = 0; i < n; i++) {
        cin >> ks[i];
    }
    cin >> raw;
    return true;
}

char before(char r, int b) {
    int i = kmap[r];
    return rkmap[(i + 52 - b) % 52];
}

void solve() {
    string ans = raw;
    int kindex = 0;
    for (int i = 0; i < raw.size(); i++) {
        ans[i] = before(raw[i], ks[kindex]);
        kindex = (kindex + 1 + n) % n;
    }
    cout << ans << endl;
}

int main() {
    init_();
    while (init()) {
        solve();
    }
    return 0;
}