def main():
    n, m = map(int, input().split())
    ans = -1
    lst = [None]*m
    for i in range(m):
        s, c = map(int, input().split())
        lst[i] = [s, c]
    for i in range(1, 1000):
        f = True
        if len(str(i)) != n:
            f = False
            continue
        for v in lst:
            if str(i)[v[0]-1] != str(v[1]):
                f = False
        if f:
            ans = i
            break
    if ans != -1:
        print(ans)
    else:
        print("-1")

if __name__ == "__main__":
    main()