#include <bits/stdc++.h>
using namespace std;
int get_int(char ch) { return ch - '0'; }
int main() {
  int n;
  int a[109];
  char s[10];
  int sec, h, m, prev = 0, max = 0, fsec;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    h = get_int(s[0]) * 10 + get_int(s[1]);
    m = get_int(s[3]) * 10 + get_int(s[4]);
    sec = 60 * m + 3600 * h;
    a[i] = sec;
  }
  sort(a, a + n);
  for (int i = 1; i < n; i++) {
    sec = a[i];
    prev = a[i - 1] + 60;
    if (sec - prev > max) max = sec - prev;
  }
  if ((a[0] + 24 * 60 * 60 - sec - 60) % (24 * 60 * 60) > max)
    max = (a[0] + 24 * 60 * 60 - sec - 60) % (24 * 60 * 60);
  m = max / 60;
  h = m / 60;
  m = m % 60;
  if (h < 10) cout << "0";
  cout << h;
  cout << ":";
  if (m < 10) cout << "0";
  cout << m;
  cout << endl;
  return 0;
}
