#include <bits/stdc++.h>
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1123456;
const long long MOD = 1123456769;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(time(0));
  vector<int> v;
  int n, m, i, h;
  char c;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> h >> c >> m;
    v.push_back(h * 60 + m);
  }
  sort(v.begin(), v.end());
  v.push_back(24 * 60 + v[0]);
  int mx = 0;
  for (i = 1; i < v.size(); i++) {
    mx = max(mx, v[i] - v[i - 1] - 1);
  }
  h = mx / 60;
  m = mx % 60;
  if (h < 10) cout << 0;
  cout << h << ":";
  if (m < 10) cout << 0;
  cout << m << "\n";
  return 0;
}
