#include <bits/stdc++.h>
int main() {
  int n, min = 999;
  char s[51] = {
      0,
  };
  char genome[5] = "ACTG";
  scanf("%d", &n);
  scanf(" %s", s);
  for (int i = 0; i < n - 3; i++) {
    int bf = 0;
    for (int j = 0; j < 4; j++) {
      int t = abs(s[i + j] - genome[j]);
      bf += t > 13 ? abs(t - 26) : t;
    }
    if (bf < min) min = bf;
  }
  printf("%d\n", min);
  return 0;
}
