import sys
import math
sys.setrecursionlimit(int(1e6))

N, M = map(int, input().split())
s = [0]*M
c = [0]*M
for i in range(M):
    s[i], c[i] = map(int, input().split())

digits = [-1]*N
fault = False
for i in range(M):
    d = s[i]-1
    if digits[d] >= 0 and (digits[d] != c[i]):
        fault = True
        break
    digits[d] = c[i]

if fault:
    print(-1)
    sys.exit()

if (N>1) and (digits[0] == 0):
    print(-1)
    sys.exit()

ans = 0
for i in range(N):
    b = 10 ** (N - i - 1)
    n = digits[i] if digits[i] >= 0 else 0
    ans = ans + n * b

min_ans = 10 ** (N - 1)
if ans < min_ans:
    ans = ans + min_ans

print(ans)
