import sys
n,m = map(int,input().split())
s = []
c = []
for i in range(m):
    ts,tc = map(int,input().split()) 
    s.append(ts)
    c.append(tc)
ans = [0]*n
c_ans = [0]*n
for i in range(m):
    if s[i] == 1 and c[i] == 0:
        print(-1)
        sys.exit()
        

for i in range(m):
    if c_ans[s[i]-1] == 1:
        if ans[s[i]-1] != c[i]:
            print(-1)
            sys.exit()
    else:
        c_ans[s[i]-1] = 1
        ans[s[i]-1] = c[i]
ans = list(map(str,ans))
# print("".join(ans))
ans2 = "".join(ans)
ans2 = int(ans2)
# print(ans)
# print(len(str(ans)))
# print(ans)
if len(str(ans2)) != n:
    ans[0] = "1"
#  print(-1)
#     sys.exit()
print("".join(ans))
