#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
int n, m;
void solve()
{
cin >> n >> m;
if (n <= m / 2) puts("0");
else if (n == m) cout << n * 2 << "\n";
else cout << (n - 1) * 2 << "\n";
return ;
}
signed main()
{
ios::sync_with_stdio(0);
solve();
return 0;
}