n,m = map(int,input().split())
sc = []
for _ in range(m):
    sc.append(list(map(int,input().split())))
tmp = [-1,-1,-1]
flag = False
for b in sc:
    s = b[0]
    c = b[1]
    if n >1 and s == 1 and c == 0:
        flag = True
        break
    if tmp[s-1] != -1 and tmp[s-1] != c:
        flag = True
        break
    tmp[s-1] = c
ans = 0
if not flag:
    for i in range(n):
        if tmp[i] == -1:
            if i == 0:
                tmp[i]=1
            else:
                tmp[i]=0
    for x in tmp:
        ans += x*(10**(n-1))
        n = n-1
else:
    ans = -1
print(ans)