# n = int(input())
# s = input()
n, m = map(int,input().split())
# da = list(map(int,input().split()))
# a = [int(input()) for i in range(n)]
da = [list(map(int,input().split())) for i in range(m)]

def ch(x):
    k = len(x)
    if n!=k: return False
    for i in range(m):
        if k < da[i][0]:
            return False
        if x[da[i][0]-1] != str(da[i][1]):
            return False
    return True

def solve():
    for i in range(10**n-1):
        if(ch(str(i))):
            print(i)
            return
    print(-1)
    return

solve()