import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
l = []
for i in range(m):
    l.append(list(map(int, input().split())))


for i in range(m):
    if n == 1:
        l[i][0] = 0
    if n == 2:
        if l[i][0] == 2:
            l[i][0] = 0
    if n == 3:
        if l[i][0] == 1:
            l[i][0] = 2
        elif l[i][0] == 2:
            l[i][0] = 1
        elif l[i][0] == 3:
            l[i][0] = 0

count = {"1nokurai": 10, "10nokurai": 10, "100nokurai": 10}
for i in range(m):
    if l[i][0] == 0:
        if count["1nokurai"] == 10 or count["1nokurai"] == l[i][1]:
            count["1nokurai"] = l[i][1]
        else:
            print(-1)
            quit()
    elif l[i][0] == 1:
        if count["10nokurai"] == 10 or count["10nokurai"] == l[i][1]:
            count["10nokurai"] = l[i][1]
        else:
            print(-1)
            quit()
    elif l[i][0] == 2:
        if count["100nokurai"] == 10 or count["100nokurai"] == l[i][1]:
            count["100nokurai"] = l[i][1]
        else:
            print(-1)
            quit()

if n == 3:
    if count["100nokurai"] == 0:
        print(-1)
        quit()
    if m == 0:
        print("100")
        quit()
if n == 2:
    if count["10nokurai"] == 0:
        print(-1)
        quit()
    if m == 0:
        print("10")
        quit()
if n == 1:
    if m == 0:
        print("0")
        quit()


if count["1nokurai"] == 10:
    count["1nokurai"] = 0
if count["10nokurai"] == 10:
    if n == 2
        count["10nokurai"] = 1
    if n == 2
        count["10nokurai"] = 0

if count["100nokurai"] == 10:
    count["100nokurai"] = 1

if n == 3:
    print(str(count["100nokurai"]) +
          str(count["10nokurai"])+str(count["1nokurai"]))
if n == 2:
    print(str(count["10nokurai"])+str(count["1nokurai"]))
if n == 1:
    print(str(count["1nokurai"]))


### FIXED CODE ###

import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
l = []
for i in range(m):
    l.append(list(map(int, input().split())))


for i in range(m):
    if n == 1:
        l[i][0] = 0
    if n == 2:
        if l[i][0] == 2:
            l[i][0] = 0
    if n == 3:
        if l[i][0] == 1:
            l[i][0] = 2
        elif l[i][0] == 2:
            l[i][0] = 1
        elif l[i][0] == 3:
            l[i][0] = 0

count = {"1nokurai": 10, "10nokurai": 10, "100nokurai": 10}
for i in range(m):
    if l[i][0] == 0:
        if count["1nokurai"] == 10 or count["1nokurai"] == l[i][1]:
            count["1nokurai"] = l[i][1]
        else:
            print(-1)
            quit()
    elif l[i][0] == 1:
        if count["10nokurai"] == 10 or count["10nokurai"] == l[i][1]:
            count["10nokurai"] = l[i][1]
        else:
            print(-1)
            quit()
    elif l[i][0] == 2:
        if count["100nokurai"] == 10 or count["100nokurai"] == l[i][1]:
            count["100nokurai"] = l[i][1]
        else:
            print(-1)
            quit()

if n == 3:
    if count["100nokurai"] == 0:
        print(-1)
        quit()
    if m == 0:
        print("100")
        quit()
if n == 2:
    if count["10nokurai"] == 0:
        print(-1)
        quit()
    if m == 0:
        print("10")
        quit()
if n == 1:
    if m == 0:
        print("0")
        quit()


if count["1nokurai"] == 10:
    count["1nokurai"] = 0
if count["10nokurai"] == 10:
    if n == 2:
        count["10nokurai"] = 1
    if n == 3:
        count["10nokurai"] = 0

if count["100nokurai"] == 10:
    count["100nokurai"] = 1

if n == 3:
    print(str(count["100nokurai"]) +
          str(count["10nokurai"])+str(count["1nokurai"]))
if n == 2:
    print(str(count["10nokurai"])+str(count["1nokurai"]))
if n == 1:
    print(str(count["1nokurai"]))