def f():
    n, m = list(map(int, input().split()))
    a = [-1, -1, -1, -1]
    if(m == 0):
        if(n == 0):
            return 0
        return pow(10, n-1)


    for c in range(m):
        x = list(map(int, input().split()))
        if(a[x[0]] == -1):
            a[x[0]] = x[1]
        else:
            if(a[x[0]] != x[1]):
                return -1
    for y in range(4):
        if(a[y] == -1):
            a[y] = 0
            if y == 1:
                a[y] = 1

    if(n > 1 and a[1] == 0):
        return -1

    if(n == 1):
        return a[1]
    if(n == 2):
        return a[1]*10 + a[2]
    if(n == 3):
        return a[1]*100 + a[2]*10 + a[3]


    




x = f()
if(x == -1):
  print("-1")
else:
  print(x)