import collections

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

sc = [tuple(map(int, input().split())) for i in range(M)]

t = collections.defaultdict(int)

flag = True

for s, c in sc:

    if s in t and t[s] != c:

        flag = False

        break

    else:

        t[s] = c



if flag:

    ans = []

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

        if i in t:

            if i == 1 and t[i] == 0 and N > 1:

                print((-1))

                exit(0)

            else:

                ans.append(t[i])

        else:

            if i != 1:

                ans.append(0)

            else:

                if N == 1:

                    ans.append(0)

                else:

                    ans.append(1)



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

else:

    print((-1))

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

d = dict()

for i in range(M):

  a,b=list(map(int,input().split()))

  if a not in d:

    d[a]=b

  else:

    if d[a]!=b:

      print((-1))

      exit(0)

tmp=0

for i in range(10):

  if 3 in d and d[3] != i:

    continue

  for j in range(10):

    if 2 in d and d[2] != j:

      continue

    for k in range(10):

      if N!=1 and k ==0:

        continue

      if 1 in d and d[1]!= k:

        continue

      print(((str(k)+str(j)+str(i))[:N]))

      exit(0)

print((-1))
import collections

N, M = list(map(int, input().split()))
sc = [tuple(map(int, input().split())) for i in range(M)]
t = collections.defaultdict(int)
flag = True
for s, c in sc:
    if s in t and t[s] != c:
        flag = False
        break
    else:
        t[s] = c
if flag:
    ans = []
    for i in range(1, N + 1):
        if i in t:
            if i == 1 and t[i] == 0 and N > 1:
                print((-1))
                exit(0)
            else:
                ans.append(t[i])
        else:
            if i != 1:
                ans.append(0)
            else:
                if N == 1:
                    ans.append(0)
                else:
                    ans.append(1)
    print(("".join(map(str, ans))))
else:
    print((-1))

N, M = list(map(int, input().split()))
d = dict()
for i in range(M):
    a, b = list(map(int, input().split()))
    if a not in d:
        d[a] = b
    else:
        if d[a] != b:
            print((-1))
            exit(0)
tmp = 0
for i in range(10):
    if 3 in d and d[3] != i:
        continue
    for j in range(10):
        if 2 in d and d[2] != j:
            continue
        for k in range(10):
            if N != 1 and k == 0:
                continue
            if 1 in d and d[1] != k:
                continue
            print(((str(k) + str(j) + str(i))[:N]))
            exit(0)
print((-1))

-import collections - -sc = [tuple(map(int, input().split())) for i in range(M)] -t = collections.defaultdict(int) -flag = True -for s, c in sc: -    if s in t and t[s] != c: -        flag = False -        break +d = dict() +for i in range(M): +    a, b = list(map(int, input().split())) +    if a not in d: +        d[a] = b -        t[s] = c -if flag: -    ans = [] -    for i in range(1, N + 1): -        if i in t: -            if i == 1 and t[i] == 0 and N > 1: -                print((-1)) -                exit(0) -            else: -                ans.append(t[i]) -        else: -            if i != 1: -                ans.append(0) -            else: -                if N == 1: -                    ans.append(0) -                else: -                    ans.append(1) -    print(("".join(map(str, ans)))) -else: -    print((-1)) +        if d[a] != b: +            print((-1)) +            exit(0) +tmp = 0 +for i in range(10): +    if 3 in d and d[3] != i: +        continue +    for j in range(10): +        if 2 in d and d[2] != j: +            continue +        for k in range(10): +            if N != 1 and k == 0: +                continue +            if 1 in d and d[1] != k: +                continue +            print(((str(k) + str(j) + str(i))[:N])) +            exit(0) +print((-1))