import sys
import math
import itertools
import collections
import heapq
import numpy as np

rl = sys.stdin.readline

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

a = [-1] * 3
isOk = False
for _ in range(m):
    b = list(map(int, rl().split()))
    if a[b[0]-1] != -1 and a[b[0]-1] != b[1]:
        isOk = True
        break
    a[b[0]-1] = b[1]

if isOk:
    print(-1)
else:
    ans = 0
    a.reverse()
    for i in range(3):
        if a[i] == -1:
            a[i] = 0
        ans += a[i]*(10**(i))
    print(ans)

