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

ans = ['0']*(n+1)
flg = 0
for i in range(m):
    if ans[sc[i][0]] == '0':
        if sc[i][1] != 0:
            ans[sc[i][0]] = str(sc[i][1])
            if sc[i][0] == 1:
                flg = 1
        elif sc[i][0] == 1 and sc[i][1] == 0 and flg == 0:
            ans[sc[i][0]] = str(sc[i][1])
            flg = 1
        else:
            continue
    elif ans[sc[i][0]] == str(sc[i][1]):
        continue
    elif ans[sc[i][0]] > str(sc[i][1]):
        ans[sc[i][0]] = str(sc[i][1])
    else:
        print(-1)
        exit()
if flg == 0:
    ans[1] = '1'
    print(int(''.join(ans)))
elif ans[1] == '0' and len(ans) != 2:
    print(-1)
else:
    print(int(''.join(ans)))
