#include <bits/stdc++.h>
using namespace std;
template <typename T>
T sqr(T a) {
  return a * a;
}
const int N = 100002;
const int ST = 20;
const long long md = 1000000007;
int a[N], n;
string s;
int res = 1e9;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  cin >> n;
  cin >> s;
  string const need = "ACTG";
  for (int i = 0; i < n; ++i) {
    int curr_res = 0;
    for (int j = 0; j < 4; ++j) {
      if (i + j >= n) {
        curr_res += 1000;
        continue;
      }
      curr_res +=
          min({abs(s[i + j] - need[j]), ('Z' - s[i + j]) + (need[j] - 'A') + 1,
               (s[i + j] - 'A') + ('Z' - need[j]) + 1});
    }
    res = min(res, curr_res);
  }
  cout << res;
  return 0;
}
