def main():
    n, m = list(map(int, input().split()))
    r = [-1] * n
    for _ in range(m):
        i, v = map(int, input().split())
        if r[i-1] == -1:
            r[i-1] = v
        elif r[i-1] != v:
            print(-1)
            return
    r = [0 if i == -1 else i for i in r]
    r = "".join(map(str, r))
    if r[0] == "0":
        print(-1)
    else:
        print(r)

if __name__ == '__main__':
    main()