n = int(input()) s = input() c = sum(s.count(e) for e in "AGCT") - 1 l = max(0, min(s.find(e) for e in "AGCT")) r = max(0, max(s.rfind(e) for e in "AGCT")) if c == 0: print(0) else: # print(c, l, r) print(max(c, l, r) - min(c, l, r) + 1)