/*
1.认真读题还是需要训练的
2.检查的时候最好手动模拟一遍吧
3.
*/

#include <bits/stdc++.h>
using namespace std;

void solve()
{
    string s;cin>>s;string t;cin>>t;
    int res = 100000000;
    // 计算字符相减的绝对值相加之和
    int n = t.length(),m = s.length();
    for (int i = 0;i < n-m+1;i++)
    {
        int temp = 0;
        for (int j = 0;j < m;j++)
        {
            temp+=min(abs(t[i+j]-s[j]),26-abs(t[i+j]-s[j]));
        }
        res = min(temp,res);
    }
    cout<<res<<'\n';
}
int main(){ios::sync_with_stdio(false);cin.tie(nullptr);solve();return 0;}