#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, br = 0, a, b;
    bool ind = false;
    //string s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    scanf("%d", &n);
    string s;

    cin >> s;
    a = s.find("A");
    for (int i = n-1; i > a; i--){
        if(s[i] == 'Z'){
            b = i;
            break;
        }
    }
    if(n <= 26 || (b - a + 1) < 26) cout << 0;
    else if((b - a + 1) == 26) cout << 1;
    else if((b - a + 1) == 27){
        for (int i = a; i < b; i++){
            if(s[i] == s[i+1]) ind = true;
        }
        if(ind) cout << 2;
        else cout << 1;

    }
    else cout << 4;




    return 0;
}