#include <iostream>
using namespace std;
int main() {
long long x, y;
cin >> x >> y;
long long n = y / 2 + 1;
x = x > y - 1 ? y - 1 : x;
long long ret = x - n;
cout << (ret < 0 ? 0 : ret + 1) << endl;
return 0;
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long x = sc.nextLong();
long y = sc.nextLong();
long n = y / 2 + 1;
x = Math.min(x, y - 1);
long ret = x - n;
System.out.println(ret < 0 ? 0 : ret + 1);
}
}
x, y = map(int, input().split())
n = y // 2 + 1
x = min(x, y - 1)
ret = x - n
print(0 if ret < 0 else ret + 1)