#include <bits/stdc++.h>
using namespace std;
string genom = "ACTG";
long long check(string a) {
  long long ans = 0;
  for (long long i = 0; i < 4; ++i) {
    ans += min((genom[i] - a[i] + 26) % 26, (a[i] - genom[i] + 26) % 26);
  }
  return ans;
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long mi = 1e18;
  for (long long i = 0; i < n - 3; ++i) mi = min(mi, check(s.substr(i, 4)));
  cout << mi;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
