#include <bits/stdc++.h>
using namespace std;
void init() { return; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  init();
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 100005;
  for (int i = 0; i < n - 3; i++) {
    int x = 0;
    x += min('Z' - s[i] + 1, min(abs(s[i] - 'A'), s[i] - 'A' + 26));
    x += min('Z' - s[i + 1] + 3, min(abs(s[i + 1] - 'C'), s[i + 1] - 'A' + 24));
    x += min('Z' - s[i + 2] + 20, min(abs(s[i + 2] - 'T'), s[i + 2] - 'A' + 7));
    x += min('Z' - s[i + 3] + 7, min(abs(s[i + 3] - 'G'), s[i + 3] - 'A' + 20));
    ans = min(ans, x);
  }
  cout << ans;
  return 0;
}
