n,m = map(int,input().split())

num = [0]*n
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:
        print(-1)
        exit()

if num[0] == 0:
    print(-1)
    exit()
    
num_ =''
num = list(map(str,num))
for i in range(n):
    num_ += num[i]

print(int(num_))
