import sys
input = sys.stdin.readline

N, M = list(map(int, input().split()))  

use = [False] * M
num = [0] * N

for i in range(M):
    s, c = list(map(int, input().split()))
    s -= 1
    if use[s] and num[s] != c: print(-1); sys.exit()

    use[s] = True
    num[s] = c

ans = int(''.join(map(str, num)))
if ans == 0: print(-1)
else: print(ans)
