#include <bits/stdc++.h>
using namespace std;
string porownaj(string a, string b) {
  if (a[0] > b[0])
    return "1";
  else if (a[0] != b[0])
    return "2";
  if (a[1] > b[1])
    return "1";
  else if (a[1] != b[1])
    return "2";
  if (a[3] > b[3])
    return "1";
  else if (a[3] != b[3])
    return "2";
  if (a[4] > b[4])
    return "1";
  else if (a[0] != b[0])
    return "2";
  else
    return "0";
}
int getminutes(string t1, string t2) {
  bool t = false;
  if (porownaj(t1, t2) == "1") {
    t = true;
    swap(t1, t2);
  }
  int hh1 = t1[0] - '0';
  int hh2 = t1[1] - '0';
  int mm1 = t1[3] - '0';
  int mm2 = t1[4] - '0';
  int hour1 = (hh1 * 10 + hh2);
  int minutes1 = (mm1 * 10 + mm2);
  int hh1a = t2[0] - '0';
  int hh2a = t2[1] - '0';
  int mm1a = t2[3] - '0';
  int mm2a = t2[4] - '0';
  int hour2 = (hh1a * 10 + hh2a);
  int minutes2 = (mm1a * 10 + mm2a);
  int ilegodzin = hour2 - hour1;
  if (ilegodzin < 0) ilegodzin = 24 - ilegodzin;
  int ileminut = minutes2 - minutes1;
  int ans = ilegodzin * 60 + ileminut;
  if (t == true) ans = 1440 - ans;
  return ans;
}
string konwertuj(int val) {
  int ilehours = val / 60;
  int ileminutes = val - (val / 60) * 60;
  stringstream ss;
  ss << ilehours;
  string wynik1 = ss.str();
  stringstream ss2;
  ss2 << ileminutes;
  string wynik2 = ss2.str();
  string skladnik1 = "";
  string skladnik2 = "";
  if (wynik1.length() == 1) skladnik1 += '0';
  if (wynik2.length() == 1) skladnik2 += '0';
  skladnik1 += wynik1;
  skladnik2 += wynik2;
  return skladnik1 + ':' + skladnik2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int maximum = 0;
  string tab[n];
  for (int i = 0; i < n; i++) {
    cin >> tab[i];
  }
  sort(tab, tab + n);
  if (n == 1) {
    cout << "23:59";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (tab[i] == tab[(i + 1) % n]) continue;
    maximum = max(maximum, getminutes(tab[i], tab[(i + 1) % n]) - 1);
  }
  string wynik = konwertuj(maximum);
  cout << wynik;
  return 0;
}
