#ifdef DEBUG
#  define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include "testlib.h"
#define ff first
#define ss second
#define szof(x) ((int)x.size())
#ifndef LOCAL
#  define cerr __get_ce
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

int main(int argc, char* argv[]) {
	registerValidation(argc, argv);

	int n = inf.readInt(1, 20, "n");
	inf.readEoln();

	int last = -1;
	for (int i = 0; i < n; i++) {
		string s = inf.readLine("[0-9]{1}:[0-9]{2}", "alarm " + to_string(i + 1));
		int h = (int) (s[0] - '0');
		int m = (int) (s[2] - '0') * 10 + (int) (s[3] - '0');
		ensuref(7 <= h && h <= 9, "h = %d, must be between 7 and 9", h);
		ensuref(m <= 59, "mm = %d, must not exceed 59", m);
		if (h == 9) {
			ensuref(m == 0, "since h = 9, m must be equal to 0, but m = %d instead", m);
		}
		int cur = h * 60 + m;
		ensuref(last < cur, "chronological order not satisfied for alarms %d and %d", i, i + 1);
		last = cur;
	}

	inf.readEof();

	return 0;
}
