N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
rank = 0
flag = True
ans = 1000
for i in range(M):
    rank = 10**(3 - L[i][0])  
    if (ans//rank) % 10 == 0:
        ans += L[i][1] * (10**(3 - L[i][0]))
    elif (ans//rank) % 10 == L[i][1]:
        None
    else:
        flag = False
        break

ans = ans - 1000

if flag == False or ans == 0:
    print(-1)
else:
    print(ans)