#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  while (cin >> n) {
    string s;
    cin >> s;
    vector<int> v;
    for (int i = 0; i < n - 3; i++) {
      int sum = 0;
      int a = abs((s[i] - 64) - 1);
      int b = abs((26 - (s[i] - 64)) + 1);
      sum += min(a, b);
      a = abs((s[i + 1] - 64) - 3);
      b = abs((26 - (s[i + 1] - 64)) + 3);
      sum += min(a, b);
      a = abs((s[i + 2] - 64) - 20);
      b = abs(26 - 20) + (s[i + 2] - 64);
      sum += min(a, b);
      a = abs((s[i + 3] - 64) - 7);
      b = abs(26 - (s[i + 3] - 64)) + 7;
      sum += min(a, b);
      v.push_back(sum);
    }
    sort(v.begin(), v.end());
    cout << v[0] << endl;
  }
  return 0;
}
