#include <bits/stdc++.h>
#pragma GCC target("sse4.2")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dr[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dc[] = {1, 0, 0, -1, 1, -1, -1, 1};
long long exp(long long n, long long m, long long md) {
  long long a = 1;
  while (m > 0) {
    if (m & 1) a = (a * n % md) % md;
    m /= 2;
    n = (n * n) % md;
  }
  return a % md;
}
void disp(vector<long long> v) {
  for (auto u : v) cout << u << " ";
  cout << "\n";
}
int getSqr(int x) {
  if (x < 0) return -1;
  int l = sqrt(x);
  for (int i = -2; i <= 2; ++i)
    if (l + i >= 0 && (l + i) * (l + i) == x) return l;
  return -1;
}
void go2() {
  int n, i, j, k;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    string s;
    cin >> s;
    int t = 0;
    t += 60 * 10 * ((int)(s[0] - '0')) + 60 * ((int)(s[1] - '0')) +
         10 * ((int)(s[3] - '0')) + ((int)(s[4] - '0'));
    a[i] = t;
  }
  if (n == 1) {
    cout << "23:59"
         << "\n";
    return;
  }
  sort(a, a + n);
  int mx = 0;
  for (i = 0; i < n - 1; i++) {
    mx = max(mx, a[i + 1] - a[i] - 1);
  }
  mx = max(mx, 1440 - a[n - 1] + a[0] - 1);
  cout << (mx / 60 < 10 ? "0" : "") << mx / 60 << ":"
       << (mx % 60 < 10 ? "0" : "") << mx % 60 << "\n";
}
void go1() {
  long long n, p;
  cin >> n >> p;
  vector<long long> ans;
  long long a[n], i, j, k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long c = a[n - 1] - n;
  long long cc = c + 1;
  c = max(0LL, c);
  long long mx = 0, mn = 1e9 + 1;
  {
    long long d = 0;
    bool ok = true;
    while (d < n) {
      long long f = upper_bound(a, a + n, c + d) - a;
      f -= d;
      mx = max(mx, f);
      mn = min(mn, f);
      if (f < 0 || f % p == 0) {
        ok = false;
        break;
      }
      d++;
    }
  }
  while (mx < p) {
    cout << mx << " " << mn << " " << c << "\n";
    if (mn > 0 && mx < p) {
      ans.push_back(c);
    }
    mx++;
    mn++;
    c++;
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << "\n";
  disp(ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long tt = 1;
  while (tt--) {
    go2();
  }
  return 0;
}
