#include <bits/stdc++.h>
int main(void) {
  int n, sum = 0, num[55], min = 100;
  char s[55];
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n - 3; i++) {
    if (abs(s[i] - 'A') <= 13) {
      sum += abs(s[i] - 'A');
    } else {
      sum += 26 - abs(s[i] - 'A');
    }
    if (abs(s[i + 1] - 'C') <= 13) {
      sum += abs(s[i + 1] - 'C');
    } else {
      sum += 26 - abs(s[i + 1] - 'C');
    }
    if (abs(s[i + 2] - 'T') <= 13) {
      sum += abs(s[i + 2] - 'T');
    } else {
      sum += 26 - abs(s[i + 2] - 'T');
    }
    if (abs(s[i + 3] - 'G') <= 13) {
      sum += abs(s[i + 3] - 'G');
    } else {
      sum += 26 - abs(s[i + 3] - 'G');
    }
    num[i] = sum;
    sum = 0;
  }
  for (int i = 0; i < n - 3; i++) {
    if (min > num[i]) {
      min = num[i];
    }
  }
  printf("%d", min);
  return 0;
}
