n, m = map(int,input().split())
slist = [0 for i in range(m)]
clist = [0 for i in range(m)]
num = [0 for i in range(n)]

flag = True

for i in range(m):
    s, c = map(int,input().split())
    if num[s-1] == 0:
        num[s-1] = c
    elif num[s-1] != c:
        flag = False

    if not flag:
        break

if flag and num[n-1] != 0:
    print(int(''.join(map(str, num))))
else:
    print(-1)
