import numpy as np
list_int = [int(e) for e in input().split()]
N = list_int[0]
M = list_int[1]
s = []
for i in range(M):
    s.append([int(e) for e in input().split()])
a = np.ones(N)*-1
flg = 0
for i in s:
    if i[0] == 1 and i[1]==0:
        print(-1)
        flg=-1
        break
    if a[i[0]-1] != -1 and a[i[0]-1] != i[1]:
        flg = 1
        print(-1)
        break
    else:
        a[i[0]-1] = i[1]
ans = 0
a = a.tolist()
a.reverse()
for i in range(N):
    if a[i]==-1:
        ans += 0
    else:
        ans += a[i]*(10**(i))
        
if flg == 0:
        print(int(ans))