n, m = map(int,input().split())
a = [-1]*n
for i in range(m):
    s, c = map(int,input().split())
    if a[s-1] >= 0:
        if a[s-1] != c:
            print(-1)
            exit()
    else:
        a[s-1] = c

if n == 1 and a[0] == 0:
    print(0)
    exit()
    
ans = ''
for i, t in enumerate(a):
    if i == 0:
        if t == 0:
            print(-1)
            exit()
    if t >= 0:
        ans += str(t)
    else:
        ans += '0'
    
if ans[0] == '0':
    print(-1)
    exit()
print(ans)