n, m = map(int, input().split())
dct = {}
exist = True
for _ in range(m):
    s, c = map(int, input().split())
    if n != 1 and s == 1 and c == 0:
        exist = False

    if s in dct.keys():
        if dct[s] != c:
            exist = False
    else:
        dct[s] = c

if not (1 in dct.keys()):
    dct[1] = 1

if exist:
    ans = 0
    for s, c in dct.items():
        ans += c*10**(n-s)
    print(ans)
else:
    print(-1)