#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  string s;
  int i, j, n, k;
  cin >> n >> s;
  int cost, min_cost = INT_MAX, tmp, tmp_, min_tmp;
  map<int, int> map_;
  map_[0] = 'A';
  map_[1] = 'C';
  map_[2] = 'T';
  map_[3] = 'G';
  for (i = 0; i <= n - 4; i++) {
    cost = 0;
    for (j = 0; j < 4; j++) {
      if (i + j >= n) continue;
      tmp = s[i + j] - 'A';
      tmp_ = map_[j] - 'A';
      if (tmp == tmp_) continue;
      min_tmp = INT_MAX;
      for (k = 1; k <= 26; k++) {
        if ((tmp + k) % 26 == tmp_) {
          min_tmp = k;
          break;
        }
      }
      for (k = 1; k <= 26; k++) {
        if ((tmp - k + 26) % 26 == tmp_) {
          min_tmp = min(min_tmp, k);
          break;
        }
      }
      cost += min_tmp;
    }
    min_cost = min(min_cost, cost);
  }
  cout << min_cost << '\n';
  return 0;
}
