from collections import defaultdict



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

SC = [list(map(int, input().split())) for _ in range(M)]



d = defaultdict(list)

for s, c in SC:

    d[s].append(c)





if any(len(set(v)) > 1 for v in list(d.values())):

    print((-1))

elif d[1] == [0] and N > 1:

    print((-1))

elif N == 1 and M == 0:

    print((0))

else:

    ans = [0] * N

    ans[0] = 1

    for i in range(N):

        if d[i + 1]:

            ans[i] = d[i + 1].pop()

            

    print(("".join(list(map(str, ans)))))



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

X = [list(map(int, input().split())) for _ in range(M)]



cand = [-1] * N

flag = False

for s, c in X:

    s -= 1

    if cand[s] == -1:

        cand[s] = c

    elif cand[s] != c:

        flag = True



if flag or (N > 1 and cand[0] == 0):

    print((-1))

else:

    ans = 0

    for i in range(N):

        if cand[i] == -1:

            if i == 0 and N > 1:

                cand[i] = 1

            else:

                cand[i] = 0

        ans += cand[i] * 10 ** (N - i - 1)

    print(ans)

from collections import defaultdict

N, M = list(map(int, input().split()))
SC = [list(map(int, input().split())) for _ in range(M)]
d = defaultdict(list)
for s, c in SC:
    d[s].append(c)
if any(len(set(v)) > 1 for v in list(d.values())):
    print((-1))
elif d[1] == [0] and N > 1:
    print((-1))
elif N == 1 and M == 0:
    print((0))
else:
    ans = [0] * N
    ans[0] = 1
    for i in range(N):
        if d[i + 1]:
            ans[i] = d[i + 1].pop()
    print(("".join(list(map(str, ans)))))

N, M = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(M)]
cand = [-1] * N
flag = False
for s, c in X:
    s -= 1
    if cand[s] == -1:
        cand[s] = c
    elif cand[s] != c:
        flag = True
if flag or (N > 1 and cand[0] == 0):
    print((-1))
else:
    ans = 0
    for i in range(N):
        if cand[i] == -1:
            if i == 0 and N > 1:
                cand[i] = 1
            else:
                cand[i] = 0
        ans += cand[i] * 10 ** (N - i - 1)
    print(ans)

-from collections import defaultdict - -SC = [list(map(int, input().split())) for _ in range(M)] -d = defaultdict(list) -for s, c in SC: -    d[s].append(c) -if any(len(set(v)) > 1 for v in list(d.values())): +X = [list(map(int, input().split())) for _ in range(M)] +cand = [-1] * N +flag = False +for s, c in X: +    s -= 1 +    if cand[s] == -1: +        cand[s] = c +    elif cand[s] != c: +        flag = True +if flag or (N > 1 and cand[0] == 0): -elif d[1] == [0] and N > 1: -    print((-1)) -elif N == 1 and M == 0: -    print((0)) -    ans = [0] * N -    ans[0] = 1 +    ans = 0 -        if d[i + 1]: -            ans[i] = d[i + 1].pop() -    print(("".join(list(map(str, ans))))) +        if cand[i] == -1: +            if i == 0 and N > 1: +                cand[i] = 1 +            else: +                cand[i] = 0 +        ans += cand[i] * 10 ** (N - i - 1) +    print(ans)