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 reach[s] == True:
            print(-1)
            return
        if int(ans[s]) == 0:
            ans[s] = str(c)
            reach[s] = True
        elif int(ans[s]) != c:
            print(-1)
            return

    jans = "".join(ans)
    if len(str(int(jans))) != n:
        print(-1)
        return
    print(jans)

if __name__ == '__main__':
    main()
