# -*- coding: utf-8 -*-
n, m = map(int, input().split())
ds = [-1 for _ in range(n)]
f = True
for _ in range(m):
    si, ci = map(int, input().split())
    si -= 1
    if ds[si] == -1:
        ds[si] = ci
    elif ds[si] == ci:
        continue
    else:
        f = False

if f:
    if len(ds) == 1:
        s = ds[0]
    elif ds[0] == 0:
        s = -1
    else:
        s = max(1, ds[0])
        for i in ds[1:]:
            s *= 10
            s += max(0, i)
    print(s)    
else:
    print(-1)
