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

from collections import defaultdict

sc = defaultdict(set)

for _ in range(M):

    s,c = list(map(int,input().split()))

    sc[s].add(c)





if N == 1:

    if len(sc[1]) > 1:

        print((-1))

    elif len(sc[1]) == 1:

        print((sc[1].pop()))

    else:

        print((0))

    exit()



ans = ""

for i in range(1,N+1):

    if len(sc[i]) > 1:

        print((-1))

        exit()



    if i == 1:

        if len(sc[i]) == 1:

            tmp = sc[i].pop()

            if tmp == 0:

                print((-1))

                exit()

            else:

                ans += str(tmp)

        else:

            ans += "1"

    else:

        if len(sc[i]) == 1:

            ans += str(sc[i].pop())

        else:

            ans += "0"



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

from collections import defaultdict

SC = defaultdict(set)

for _ in range(M):

    s,c = list(map(int, input().split()))

    SC[s].add(c)



if N == 1:

    if len(SC[1]) > 1:

        ans = -1

    elif len(SC[1]) == 1:

        ans = SC[1].pop()

    else:

        ans = 0

    print(ans)

    exit()



ans = ""

for i in range(1, N + 1):

    if len(SC[i]) > 1:

        ans = -1

        break



    if i == 1:

        if len(SC[i]) == 1:

            tmp = SC[i].pop()

            if tmp == 0:

                ans = -1

                break

            else:

                ans += str(tmp)

        else:

            ans += "1"

    else:

        if len(SC[i]) == 1:

            ans += str(SC[i].pop())

        else:

            ans += "0"



print(ans)
N, M = list(map(int, input().split()))
from collections import defaultdict

sc = defaultdict(set)
for _ in range(M):
    s, c = list(map(int, input().split()))
    sc[s].add(c)
if N == 1:
    if len(sc[1]) > 1:
        print((-1))
    elif len(sc[1]) == 1:
        print((sc[1].pop()))
    else:
        print((0))
    exit()
ans = ""
for i in range(1, N + 1):
    if len(sc[i]) > 1:
        print((-1))
        exit()
    if i == 1:
        if len(sc[i]) == 1:
            tmp = sc[i].pop()
            if tmp == 0:
                print((-1))
                exit()
            else:
                ans += str(tmp)
        else:
            ans += "1"
    else:
        if len(sc[i]) == 1:
            ans += str(sc[i].pop())
        else:
            ans += "0"
print(ans)

N, M = list(map(int, input().split()))
from collections import defaultdict

SC = defaultdict(set)
for _ in range(M):
    s, c = list(map(int, input().split()))
    SC[s].add(c)
if N == 1:
    if len(SC[1]) > 1:
        ans = -1
    elif len(SC[1]) == 1:
        ans = SC[1].pop()
    else:
        ans = 0
    print(ans)
    exit()
ans = ""
for i in range(1, N + 1):
    if len(SC[i]) > 1:
        ans = -1
        break
    if i == 1:
        if len(SC[i]) == 1:
            tmp = SC[i].pop()
            if tmp == 0:
                ans = -1
                break
            else:
                ans += str(tmp)
        else:
            ans += "1"
    else:
        if len(SC[i]) == 1:
            ans += str(SC[i].pop())
        else:
            ans += "0"
print(ans)

-sc = defaultdict(set) +SC = defaultdict(set) -    sc[s].add(c) +    SC[s].add(c) -    if len(sc[1]) > 1: -        print((-1)) -    elif len(sc[1]) == 1: -        print((sc[1].pop())) +    if len(SC[1]) > 1: +        ans = -1 +    elif len(SC[1]) == 1: +        ans = SC[1].pop() -        print((0)) +        ans = 0 +    print(ans) -    if len(sc[i]) > 1: -        print((-1)) -        exit() +    if len(SC[i]) > 1: +        ans = -1 +        break -        if len(sc[i]) == 1: -            tmp = sc[i].pop() +        if len(SC[i]) == 1: +            tmp = SC[i].pop() -                print((-1)) -                exit() +                ans = -1 +                break -        if len(sc[i]) == 1: -            ans += str(sc[i].pop()) +        if len(SC[i]) == 1: +            ans += str(SC[i].pop())