import sys
N, M = map(int, input().split())

a = [-1]*N

for _ in range(M):
    s, c = map(int, input().split())
    if a[s-1] != -1 and a[s-1] != c:
        print('-1')
        sys.exit()
    else:
        a[s-1] = c

a = ['0' if x == -1 else str(x) for x in a]
if a == '000':
    print('0')
elif a[0] == '0':
    print('-1')
else:
    print(''.join(a))
