#include <bits/stdc++.h>
int find_min(int pos, int target) {
  int right = -1;
  for (int i = 0; right == -1; i++)
    if ((pos + i) % 26 == target) right = i;
  int left = -1;
  for (int i = 0; left == -1; i++)
    if ((pos - i + 26 * 2) % 26 == target) left = i;
  return std::min(right, left);
}
int main() {
  int n;
  std::cin >> n;
  std::string s;
  std::cin >> s;
  std::string genome = "ACTG";
  int min_moves = INT_MAX;
  for (int i = 0; i < n - 3; i++) {
    int min_temp = 0;
    for (int j = 0; j < 4; j++)
      min_temp += find_min(s[i + j] - 'A', genome[j] - 'A');
    min_moves = std::min(min_moves, min_temp);
  }
  std::cout << min_moves << '\n';
  return 0;
}
