n,m = list(map(int,input().split()))
s = []
c = []
for i in range(m):
    ss,cc = list(map(int,input().split()))
    s.append(ss -1 )
    c.append(cc)

ans = [-1] * n
flag = True
for i in range(m):
    if ans[s[i]] == -1 :
        ans[s[i]] = c[i]
    elif ans[s[i]] != c[i]:
        flag = False

if n !=1 and  ans[0] == 0:
    flag = False

if flag :
    ans = [ str(a) if a != -1 else "0" for a in ans ]
    if n != 1 and ans[0] == "0":
        ans[0] = 1
    print("".join(ans))
else:
    print(-1) 

