n = int(input()) point = [2] + [0] * (n - 1) # mの回数だけ更新を繰り返す場合 m = int(input()) for _ in range(m): new_point = point.copy() for i in range(n): if i == 0: left = point[n - 1] right = point[1] elif i == n - 1: left = point[n - 2] right = point[0] else: left = point[i - 1] right = point[i + 1] if left == 2 or right == 2: new_point[i] = 1 elif point[i] == 2: new_point[i] = 0 else: new_point[i] = 1 point = new_point num = point.count(2) print(num)