class FenwickTree:
    def __init__(self, size):
        self.n = size
        self.tree = [0] * (self.n + 2)  # Using n+2 to avoid issues with 1-based indexing

    def update_point(self, idx, delta):
        # Converts to 1-based index internally
        idx += 1  # since input is 0-based
        while idx <= self.n:
            self.tree[idx] += delta
            idx += idx & -idx

    def query_prefix(self, idx):
        # Sum from 0-based index 0 to idx (inclusive)
        res = 0
        idx += 1  # convert to 1-based index
        while idx > 0:
            res += self.tree[idx]
            idx -= idx & -idx
        return res

    def range_query(self, l, r):
        if l > r:
            return 0
        return self.query_prefix(r) - self.query_prefix(l - 1)

def main():
    import sys
    input = sys.stdin.read().split()
    n = int(input[0])
    s = input[1].strip()
    
    agct = [1 if c in {'A', 'G', 'C', 'T'} else 0 for c in s]
    
    valid_ft = FenwickTree(n)
    valid_agct_ft = FenwickTree(n)
    
    for i in range(n):
        valid_ft.update_point(i, 1)
        if agct[i]:
            valid_agct_ft.update_point(i, 1)
    
    count = 0
    
    def find_kth(k):
        low = 0
        high = n - 1
        res = -1
        while low <= high:
            mid = (low + high) // 2
            s = valid_ft.query_prefix(mid)
            if s >= k:
                res = mid
                high = mid - 1
            else:
                low = mid + 1
        return res
    
    while True:
        sum_agct = valid_agct_ft.query_prefix(n - 1)
        if sum_agct == 0:
            break
        k = sum_agct
        pos = find_kth(k)
        if pos == -1:
            break
        
        valid_ft.update_point(pos, -1)
        if agct[pos]:
            valid_agct_ft.update_point(pos, -1)
        count += 1
    
    print(count)

if __name__ == "__main__":
    main()