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

#N桁の数字
number = [-1 for _ in range(N)] 

for i in range(M):
    s,c = map(int,input().split())

    if number[s-1] == -1 or number[s-1] == c:
        number[s-1] = c
    else:
        #already exists
        print(-1)
        exit()

#最上位0チェック(1桁の場合はそのまま出力)
if N == 1 and number[0] == 0:
    print(0)
    exit()

if number[0] == 0:
    print(-1)
    exit()

#最上位以外の-1は0に置換（最小にするため）
for i in range(N):
    if number[i] == -1:
        number[i] = 0

if N == 2:
    print(number[0]*10+number[1])
    exit()
if N == 3:
    print(number[0]*100+number[1]*10+number[2])
    exit()
