#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const long long mod = 1e9 + 7;
const int alphabet = 26;
const int inf = INT_MAX;
const long long linf = 1e18 + 9;
namespace util {
inline long long cnm(char ch) { return (ch - '0'); }
inline long long cap(char ch) { return (ch - 'a'); }
inline void instr(string& s, long long& n) {
  cin >> s;
  n = s.length();
}
inline void instr(string& s) { cin >> s; }
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
bool min(T a, T b, T c) {
  return std::min(a, std::min(b, c));
}
}  // namespace util
using namespace util;
vector<long long> split(string line, char c) {
  vector<long long> v;
  string num = "";
  for (int i = 0; i < line.size(); i++) {
    if (line[i] == c) {
      v.push_back(stoll(num));
      num = "";
    } else
      num += line[i];
  }
  v.push_back(stoll(num));
  return v;
}
void solve(int tc) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, k, m, n;
  vector<long long> v;
  cin >> n;
  string stime;
  getline(cin, stime);
  for (i = 0; i < n; i++) {
    getline(cin, stime);
    vector<long long> vl = split(stime, ':');
    v.push_back(vl[0] * 60 + vl[1]);
  }
  sort(v.begin(), v.end());
  v.push_back(v[0] + 24 * 60);
  long long ans = -1;
  for (i = 1; i < v.size(); i++) {
    ans = max(ans, v[i] - (v[i - 1] + 1));
  }
  long long hans = (ans / (60));
  long long mans = (ans % 60);
  if (hans < 10) cout << "0";
  cout << hans;
  cout << ":";
  if (mans < 10) cout << "0";
  cout << mans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  int i = 1;
  while (i <= t) {
    solve(i);
    i++;
  }
  return 0;
}
