using namespace std;
int s[110];
int main() {
int n, m, res = 0,cnt=1;
cin >> n >> m;
int k = m / 2;
if (n <= k) { cout << 0;
return 0;
}
else {
s[1] = 1;
for (int i = 1; i <= m - 2; i+=2) {
if (cnt < n) {
s[i + 2] = 1;
cnt++;
}
}
if (cnt < n) {
for (int i = 2; i <= m - 3; i+=2) {
if (cnt < n) {
s[i + 2] = 1;
cnt++;
}
}
}
}
for (int i = 2; i <= m - 1; i++) {
if (s[i] == 1) {
if (s[i - 1] == 1) res++;
if (s[i + 1] == 1) res++;
}
}
if (s[m] == 1) res++;
if (s[2] == 1) res++;
if (s[m - 1] == 1&&s[m]==1) res++;
if (s[1] == 1&&s[m]==1) res++;
cout << res;
return 0;
}