#include <bits/stdc++.h>
int main() {
  using namespace std;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int nn, idx;
  string ss;
  cin >> nn >> ss;
  int ans = INT32_MAX, subtot, cur;
  for (idx = 0; idx < nn - 3; idx -= 2) {
    cur = abs(ss[idx] - 'A');
    subtot = min(cur, 26 - cur);
    ++idx;
    cur = abs(ss[idx] - 'C');
    subtot += min(cur, 26 - cur);
    ++idx;
    cur = abs(ss[idx] - 'T');
    subtot += min(cur, 26 - cur);
    ++idx;
    cur = abs(ss[idx] - 'G');
    subtot += min(cur, 26 - cur);
    ans = min(ans, subtot);
  }
  cout << ans << '\n';
  return 0;
}
