/*
* * author: attacker
* * created: 01.04.2026 18:07:20
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 1
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpc __builtin_popcount
#define size(v) (int)(v.size())
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, m;
cin >> n >> m;
map<string, pair<int, int>> score;
for (int i = 0; i < n + 1; i++) {
string team;
cin >> team;
pair<int, int> cur = {0, 0};
for (int j = 0; j < m; j++) {
string res;
cin >> res;
if (res[0] == '-') {
continue;
}
cur.first++;
cur.second += 20 * (res[1] - '1') * 60;
cur.second += stoi(res.substr(4, 1)) * 3600;
cur.second += stoi(res.substr(6, 2)) * 60;
cur.second += stoi(res.substr(9, 2));
}
score[team] = cur;
}
vector<tuple<string, int, int>> vt;
for (auto [team, val] : score) {
vt.push_back({team, val.first, val.second});
}
sort(vt.begin(), vt.end(), [&](tuple<string, int, int> x, tuple<string, int, int> y) {
if (get<1>(x) != get<1>(y)) {
return get<1>(x) < get<1>(y);
}
return get<2>(x) > get<2>(y);
});
string team = "NijeZivotJedanACM";
for (int i = 0; i < size(vt); i++) {
if (get<0>(vt[i]) == team) {
cout << i + 1 << '\n';
return 0;
}
}
return 0;
}