import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

def main():
    n, m = na()

    reach = [False,False,False]
    ans = ["0" for i in range(n)]
    for i in range(m):
        s, c = na()
        s -= 1
        if int(ans[s]) == 0:
            if reach[s] == False:
                reach[s] = True
            else:
                break
            ans[s] = str(c)
        elif int(ans[s]) != c:
            print(-1)
            return

    jans = int("".join(ans))
    for i in range(1, 1000):
        if i == jans:
            if len(str(i)) == n:
                print(jans)
                return
    print(-1)

if __name__ == '__main__':
    main()
