#include <bits/stdc++.h>
using namespace std;
int cnt[3600];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int h, m;
    scanf("\n%d:%d", &h, &m);
    cnt[h * 60 + m]++;
  }
  int ans = 0;
  for (int i = 0; i < 1440; i++) {
    if (cnt[i] == 0) {
      int cur = 1, j = (i + 1) % 1440;
      while (j != i && cnt[j] == 0) {
        j = (j + 1) % 1440;
        cur++;
      }
      ans = max(ans, cur);
    }
  }
  cout << (ans / 60) / 10 << (ans / 60) % 10 << ":" << (ans % 60) / 10
       << ans % 10;
  return 0;
}
