import sys
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(m)]
ls.sort()
ans = []
di=[[] for _ in range(n)]
if m == 0:
    if n == 1:
        print(0)
        sys.exit()
    else:
        print("1"+"0"*(n-1))
        sys.exit()
if n == 1:
    print(ls[0][1])
    sys.exit()
for i in range(m):
    di[ls[i][0]-1].append(ls[i][1])
for j in range(len(di)):
    if di[j] != []:
        di[j] = list(set(di[j]))
        if len(di[j]) > 1:
            print(-1)
            sys.exit()
for l in range(n):
    if l == 0:
        if di[l] == []:
            ans.append(str(1))
        elif 0 in di[l]:
            print(-1)
            sys.exit()
        else:
            ans.append(str(di[l][0]))
    else:
        if di[l] == []:
            ans.append(str(0))
        else:
            ans.append(str(di[l][0]))
print("".join(ans))

    
    
    