def main():
    n, m = map(int, input().split())
    
    ans = []
    check = []
    false_flg = 0
    for i in range(n):
        ans.append('0')
        check.append(0)

    for j in range(m):
        s, c = input().split()
        if check[int(s)-1] == 0:
            ans[int(s)-1] = c
            check[int(s)-1] = 1

        elif check[int(s)-1] == 1 and ans[int(s)-1] == c:
            if ans[int(s)-1] == 0:
                check[int(s)-1] = 1
                
        else:
            false_flg = 1
    
    tmp = int("".join(ans))
    
    if tmp // 10**(n-1) > 0 and false_flg != 1:
        print(tmp)
    else:
        print(-1)


if __name__ == '__main__':
    main()
