#include <bits/stdc++.h>
using namespace std;
int find(char cur, char target) {
  char x = cur;
  int res, cnt = 0;
  while (cur != target) {
    if (cur == 'Z')
      cur = 'A';
    else
      cur++;
    cnt++;
  }
  res = cnt;
  cnt = 0;
  cur = x;
  while (cur != target) {
    if (cur == 'A')
      cur = 'Z';
    else
      cur--;
    cnt++;
  }
  res = min(res, cnt);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  string second;
  cin >> n >> second;
  int ans = 1e9;
  for (int i = 0; i <= n - 4; i++) {
    ans = min(ans, find(second[i], 'A') + find(second[i + 1], 'C') +
                       find(second[i + 2], 'T') + find(second[i + 3], 'G'));
  }
  cout << ans;
}
