N,M = map(int,input().split())

sc = {}

def main():
    for i in range(M):
        s,c = input().split()
        s = int(s)
        if s not in sc:
            sc[s] = c
        else:
            if sc[s] != c:
                return -1
                break


    ans = ["0"] * N

    for k,n in sc.items():
        ans[k-1] = n

    result = ''.join(ans)
    if result[0] != '0' or result == '0':
        return result
    else:
        result[0] = '1'    
        return int(result)

FUCK = main()
print(FUCK)        