n,m = map(int,input().split())
li = [list(map(int,input().split())) for i in range(m)]
num = [0 for i in range(n)]
num[0] = 1
numc = [0 for i in range(n)]

for i in range(m):
    if numc[li[i][0]-1] == 0:
        num[li[i][0]-1] = li[i][1]
        numc[li[i][0]-1] += 1
    elif li[i][1] != num[li[i][0]-1]:
        num = [-1]
        break

if num[0] == 0:
    num = [-1]
print(''.join(map(str,num)))