import sys
n, m = map(int, input().split())

sc = [list(map(int, input().split())) for _ in range(m)]

result = [-1 for _ in range(n)]

for i in range(m):
    if result[sc[i][0]-1] < 0 or result[sc[i][0]-1]==sc[i][1]:
        result[sc[i][0]-1] = sc[i][1]
    else:
        print(-1)
        sys.exit()
if result[0]==0:
    print(-1)
    sys.exit()
result = [max(0,result[i]) for i in range(n)]
if result[0]==0:
    result[0]=1
print("".join(map(str, result)))