#!/usr/bin/env python3
N, M = map(int, input().split())

n = {}
exs = {}

for i in range(M):
    n[i+1] = 0
    exs[i+1]=0

f = True

for i in range(M):
    s, c = map(int, input().split())
    exs[s] += 1
    if exs[s] == 1 or c==n[s]:
        n[s] = c
    else:
        f = False
        break
ans = ''
if f:
    for k,v in n.items():
        ans += str(v)
else:
    print(-1)
    exit()

if int(ans) > 0:
    print(ans)
else:
    print(-1)



