#include<cstdio>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b;
int main()
{
cin >> a >> b;
int x = a;
int y = b;
int ans = 0;
ans = max(ans, (x % 100 + 900 - y));
ans = max(ans, ((x / 100) * 100 + 90 + x % 10) - y);
ans = max(ans, x + 9 - x % 10 - y);
ans = max(ans, x - ( y % 100 + 100));
ans = max(ans,x - ( ( y / 100 ) * 100 + y % 10));
ans = max(ans,x - ( y - y % 10));
cout << ans;
return 0;
}