#include <bits/stdc++.h>
const int N = 1e6;
const double PI = 3.14;
using namespace std;
int n, m, k, a[N], sum = 1e9, sum2 = 1e9, sum3 = 1e9;
int main() {
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n - 3; i++) {
    int x2, x3, x4;
    int x1 = min(s[i] - 'A', 'Z' - s[i] + 1);
    if (s[i + 1] >= 'C')
      x2 = min(s[i + 1] - 'C', 'Z' - s[i + 1] + 3);
    else
      x2 = min('C' - s[i + 1], s[i + 1] - 'A' + ('Z' - 'C') + 1);
    if (s[i + 2] >= 'T')
      x4 = min(s[i + 2] - 'T', 'Z' - s[i + 2] + 20);
    else
      x4 = min('T' - s[i + 2], (s[i + 2] - 'A') + ('Z' - 'T') + 1);
    if (s[i + 3] >= 'G')
      x3 = min(s[i + 3] - 'G', ('Z' - s[i + 3]) + 7);
    else
      x3 = min('G' - s[i + 3], s[i + 3] - 'A' + ('Z' - 'G') + 1);
    sum = min(sum, x1 + x2 + x3 + x4);
  }
  cout << sum;
  return 0;
}
