#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O3")
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  long long int ans = 1000000007;
  for (long long int a = 0; a < n - 3; a++) {
    long long int po = 0;
    long long int b = s[a] - 'A';
    po += min(b, 26 - b);
    b = s[a + 1] - 'A';
    b = min(llabs(b - 2), 26 - llabs(b - 2));
    po += b;
    b = s[a + 2] - 'A';
    b = min(llabs(b - 19), 26 - llabs(b - 19));
    po += b;
    b = s[a + 3] - 'A';
    b = min(llabs(b - 6), 26 - llabs(b - 6));
    po += b;
    ans = min(ans, po);
  }
  cout << ans;
  return 0;
}
