# Problem Statement : https://www.hackerrank.com/challenges/drawing-book

#!/bin/python

import sys

def solve(n, p):
    # Complete this function
    
    z = min((p/2),(n/2-p/2))
    return z
n = int(raw_input().strip())
p = int(raw_input().strip())
result = solve(n, p)
print(result)

8f1aa92f79cb56ceac92feb0363bb2f88aac38c3
<mask token>

<mask token>


def solve(n, p):
    z = min(p / 2, n / 2 - p / 2)
    return z


<mask token>
print(result)

<mask token>


def solve(n, p):
    z = min(p / 2, n / 2 - p / 2)
    return z


n = int(raw_input().strip())
p = int(raw_input().strip())
result = solve(n, p)
print(result)

import sys


def solve(n, p):
    z = min(p / 2, n / 2 - p / 2)
    return z


n = int(raw_input().strip())
p = int(raw_input().strip())
result = solve(n, p)
print(result)

# Problem Statement : https://www.hackerrank.com/challenges/drawing-book

#!/bin/python

import sys

def solve(n, p):
    # Complete this function
    
    z = min((p/2),(n/2-p/2))
    return z
n = int(raw_input().strip())
p = int(raw_input().strip())
result = solve(n, p)
print(result)
