N, M = map(int, input().split())

is_true = True
d = {}
for i in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        is_true = False
        break
    elif s not in d:
        d[s] = c
    else:
        if d[s] == c:
            continue
        else:
            is_true = False
            break

if is_true:
    for x in range(1, N+1):
        if x not in d:
            if x == 1:
                d[x] = 1
            else:
                d[x] = 0

    new = sorted(d.items())
    ans = ''
    for k in new:
        ans += str(k[1])

    if len(ans) == N:
        print(ans)
    else:
        print('-1')
else:
    print('-1')
