n, m =map(int,input().split())
a = [-1] * n
flg = True
for i in range(m):
    s, c = map(int,input().split())
    if a[s-1] == -1:
        a[s-1] = c
    elif a[s-1] == c:
        pass
    else:
        flg = False
        break
if a[0] == -1:
    flg = False

if flg:
    num = 0
    for i in range(len(a)):
        if a[i] != -1:
            num += a[i] * (10**(m-i-1))
    print(num)
else:
    print(-1)