def main():
    n, m = map(int, input().split())
    C = [-1 for _ in range(n)]
    flag = 0
    for i in range(m):
        s, c = map(int, input().split())
        if C[s - 1] == -1 or C[s - 1] == c:
            C[s - 1] = c
        else:
            flag = 1

    if flag or C[0] == 0:
        print(-1)
        return

    else:
        C = [0 if i == -1 else i for i in C]
        if C[0] == 0:
            C[0] = 1
    print(''.join(list(map(str, C))))


if __name__ == '__main__':
    main()