N, M = list(map(int, input().split(' ')))
ret = [-1 for i in range(N)]
error = False
for m in range(M):
    si, ci = list(map(int, input().split(' ')))
    if ret[si-1] == -1:
        ret[si-1] = ci
    elif ret[si-1] != ci:
        error = True
        break
tmp = ''
if not error:
    for n in range(N):
        if ret[n] == -1:
            ret[n] = 0
        tmp += str(ret[n])
    result = int(tmp)
    result = result if len(str(result)) == N else -1
else:
    result = -1
print(result)