import std.stdio, std.conv, std.string, std.range, std.math, std.bigint, std.algorithm; void main() { auto input = readln.split.to!(long[]); auto A = input[0], B = input[1]; ((A < B ? A - 1 : 2000000000 - A) + abs(B - A) - 1).writeln; }