#include <bits/stdc++.h>
using namespace std;
inline int dist(char x, char y) {
  int num1 = x - 'A', num2 = y - 'A';
  int ret = INT_MAX;
  for (int i = num2;; i++) {
    int num = i % 26;
    if (num == num1) {
      ret = i - num2;
      break;
    }
  }
  for (int i = num2;; i--) {
    int num = i;
    if (i < 0) num += 26;
    if (num == num1) {
      ret = min(ret, num2 - i);
      break;
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    if (i + 3 >= n) break;
    ans = min(ans, dist(s[i], 'A') + dist(s[i + 1], 'C') + dist(s[i + 2], 'T') +
                       dist(s[i + 3], 'G'));
  }
  cout << ans;
  return 0;
}
