class Bit: def __init__(self, n): self.size = n self.n0 = 1 << (n.bit_length() - 1) self.tree = [0] * (n + 1) def range_sum(self, l, r): return self.sum(r - 1) - self.sum(l - 1) def sum(self, i): i += 1 s = 0 while i > 0: s += self.tree[i] i -= i & -i return s def get(self, i): return self.sum(i) - self.sum(i - 1) def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i def lower_bound(self, x): pos = 0 plus = self.n0 tot = 0 while plus > 0: if pos + plus <= self.size and self.tree[pos + plus] < x: x -= self.tree[pos + plus] pos += plus plus //= 2 return pos def stupid(S): ret = 0 while 1: cnt = 0 for s in S: if s in "AGCT": cnt += 1 if cnt == 0: break ret += 1 T = S[:cnt - 1] + S[cnt:] s = S[cnt - 1] cnt2 = 0 for t in T: if t == s: cnt2 += 1 S = [] for s in T: p = ord(s) - 65 p += cnt2 p %= 26 S.append(chr(p + 65)) S = "".join(S) return ret def solve(S): n = len(S) bit = Bit(n) for i in range(n): bit.add(i, 1) cnt = [0] * 26 S = [ord(s) - 65 for s in S] for s in S: cnt[s] += 1 rot = 0 agct = [0, 6, 2, 19] ret = 0 while 1: c1 = 0 for i in agct: c1 += cnt[(i - rot) % 26] if c1 == 0: break ret += 1 p = bit.lower_bound(c1) bit.add(p, -1) cnt[S[p]] -= 1 c2 = cnt[S[p]] rot += c2 return ret n = int(input()) S = input() print(solve(S))