#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string x;
  int pnt = 0;
  int a[100000 + 10];
  for (int i = 0; i < n; i++) {
    cin >> x;
    int id = (x[0] - '0') * 10 + x[1] - '0';
    id = id * 60;
    int id2 = (x[3] - '0') * 10 + x[4] - '0';
    id += id2;
    a[i] = id;
  }
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans = max(ans, a[i + 1] - a[i] - 1);
  }
  ans = max(ans, 24 * 60 - (a[n - 1] - a[0] + 1));
  int h = ans / 60;
  int m = ans % 60;
  if (h < 10) cout << "0";
  cout << h;
  cout << ":";
  if (m < 10) cout << "0";
  cout << m;
}
