n, m = map(int, input().split())

def ng():
    print(-1)
    exit()

    
ans = [0] * 3
sc = []
for i in range(m):
    x = list(map(int, input().split()))
    sc.append(x)

sc.sort()
if sc[0][1] == 0:
    ng()
for i in range(m - 1):
    if (sc[i][0] == sc[i + 1][0]) and (sc[i][1] != sc[i + 1][1]):
        ng() 

for i in range(m):
    ans[sc[i][0] - 1] = sc[i][1]
ans2 = ''
for i in ans:
    ans2 += str(i)

print(ans2)