import sys

N, M = map(int, input().split())
num = [-1]*N

for _ in range(M):
    a, b = map(int, input().split())
    if N == 1:
        print(b)
        sys.exit()
    elif num[a-1] == -1 or num[a-1] == b:
        num[a-1] = b
    else:
        print(-1)
        sys.exit()

num = ['0' if x == -1 else str(x) for x in num]
if num[N-1] == '0':
    print('1'+''.join(num[1:]))
else:
    print(''.join(num))
