#include <bits/stdc++.h>
using namespace std;
void print(pair<int, int> v) {
  if (v.first < 10) {
    cout << "0" << v.first << ':';
  } else {
    cout << v.first << ':';
  }
  if (v.second < 10) {
    cout << "0" << v.second;
  } else {
    cout << v.second;
  }
}
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    int h, m;
    char d;
    cin >> h >> d >> m;
    v.push_back({h, m});
  }
  sort(v.begin(), v.end());
  v.push_back({v[0].first + 24, v[0].second});
  int mans = -1;
  for (int i = 0; i < v.size() - 1; i++) {
    int m = 0;
    m = (v[i + 1].first - v[i].first) * 60 + (v[i + 1].second - v[i].second) -
        1;
    mans = max(mans, m);
  }
  print({mans / 60, mans % 60});
}
