#include <bits/stdc++.h>
using namespace std;
bool pri(int a) {
  for (int i = 2; i * i <= a; i++) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
string s[300];
int n, a, b, x, y;
int f(char a) { return (int(a) - int('0')); }
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s, s + n);
  if (10 * (int(s[0][3]) - int('0')) + (int(s[0][4]) - int('0')) <
      10 * f(s[n - 1][3]) + f(s[n - 1][4]) + 1) {
    b = 10 * (int(s[0][3]) - int('0')) + (int(s[0][4]) - int('0')) -
        (10 * f(s[n - 1][3]) + f(s[n - 1][4]) + 1) + 60;
    a = 10 * (int(s[0][0]) - int('0')) + (int(s[0][1]) - int('0')) -
        (10 * f(s[n - 1][0]) + f(s[n - 1][1])) + 23;
  } else {
    b = 10 * (int(s[0][3]) - int('0')) + (int(s[0][4]) - int('0')) -
        (10 * f(s[n - 1][3]) + f(s[n - 1][4]) + 1);
    a = 10 * (int(s[0][0]) - int('0')) + (int(s[0][1]) - int('0')) -
        (10 * f(s[n - 1][0]) + f(s[n - 1][1])) + 24;
  }
  for (int i = 1; i < n; i++) {
    if (10 * (int(s[i][3]) - int('0')) + (int(s[i][4]) - int('0')) <
        10 * f(s[i - 1][3]) + f(s[i - 1][4]) + 1) {
      x = 10 * (int(s[i][3]) - int('0')) + (int(s[i][4]) - int('0')) -
          (10 * f(s[i - 1][3]) + f(s[i - 1][4]) + 1) + 60;
      y = 10 * (int(s[i][0]) - int('0')) + (int(s[i][1]) - int('0')) -
          (10 * f(s[i - 1][0]) + f(s[i - 1][1])) - 1;
    } else {
      x = 10 * (int(s[i][3]) - int('0')) + (int(s[i][4]) - int('0')) -
          (10 * f(s[i - 1][3]) + f(s[i - 1][4]) + 1);
      y = 10 * (int(s[i][0]) - int('0')) + (int(s[i][1]) - int('0')) -
          (10 * f(s[i - 1][0]) + f(s[i - 1][1]));
    }
    if (60 * y + x > 60 * a + b) {
      a = y;
      b = x;
    }
  }
  if (a < 10) cout << 0;
  cout << a << ":";
  if (b < 10) cout << 0;
  cout << b;
  return 0;
}
