import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 10**7+9
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


n,m = LI()
l = [-1]*n

for i in range(m):
    s,c = LI()
    if l[s-1]==-1:
        l[s-1] = c
    else:
        if l[s-1]!=c:
            print(-1)
            exit()

if l[0]==0:
    print(-1)
    exit()

for i in range(n):
    if i!=0:
        print(max(l[i],0),end="")
    else:
        if l[i]==-1:
            print(1,end="")
        else:
            print(l[0],end="")

print()