def main():
    n, m = map(int, input().split())
    s = [0] * n
    c = [0] * n
    for i in range(m):
        s[i], c[i] = map(int, input().split())
    ans = [None, None, None]
    for i in range(m):
        if n != 1 and s[i] == 1 and c[i] == 0:
            print(-1)
            exit()
        if ans[s[i]-1] == None:
            ans[s[i]-1] = c[i]
        if ans[s[i]-1] == c[i]:
            continue
        else:
            print(-1)
            exit()
    if ans[0] == None:
        ans[0] = 1
    if ans[1] == None:
        ans[1] = 0
    if ans[2] == None:
        ans[2] = 0
    print(*ans, sep='')

if __name__ == '__main__':
    main()