#include <iostream>
#include <string>
#include <climits>
#include <algorithm> 

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int min_operations = INT_MAX;
    int len_s = s.length();
    int len_t = t.length();

    for (int i = 0; i <= len_t - len_s; i++) {
        int operations = 0;
        for (int j = 0; j < len_s; j++) {
            if (s[j] != t[i + j]) {
                int diff = abs(s[j] - t[i + j]);
                operations += min(diff, 26 - diff);
                if (operations >= min_operations) {
                    break; 
                }
            }
        }
        if (operations < min_operations) {
            min_operations = operations;
        }
    }

    cout << min_operations << endl;
    return 0;
}