n,m = map(int,input().split())
s = [list(map(int,input().split())) for i in range(m)]
temp = [-1 for i in range(n)]
flag = True
for i in s:
    if not temp[i[0]-1] in [-1,i[1]]:
        flag = False
        break
    temp[i[0]-1] = i[1]
for i in range(n):
    if temp[i]==-1:
        temp[i] = 0
ans = ""
if flag:
    if temp[0]==0:
        temp = [-1]
    for i in temp:
        ans += str(i)
else:
    ans = "-1"
print(ans)