#include <bits/stdc++.h>
using namespace std;
string gen = "ACTG";
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0x3f3f3f3f;
  for (int i = 0; i < (n - 3); i++) {
    int c = 0;
    for (int j = 0; j < (4); j++) {
      int k = abs(s[i + j] - gen[j]);
      if (k > 13) k = abs(k - 26);
      c += k;
    }
    ans = min(ans, c);
  }
  cout << ans;
  return 0;
}
