N = int(input()) S = input() print('NO' if S in {'1', '0', '10', '01'} else 'YES')