def main():
    n, m = map(int, input().split())
    ans = [-1] * n

    for _ in range(m):
        s, c = map(int, input().split())
        s -= 1
        if (ans[s] == -1 or ans[s] == c) and not(n > 1 and s == 1 and c == 0):
            ans[s] = c
        else:
            print(-1)
            exit()

    ans = [n if n != -1 else 0 for n in ans]
    if ans[0] == 0 and n > 1:
        ans[0] = 1
    print(*ans, sep='')


if __name__ == '__main__':
    main()
