time complexity: count common values ​​in two matrices

given two sets of integers A and B of size m, with values ​​in the
range (-n, n). I want an algorithm to count how many common values ​​are
in A and B, if a value is repeated we only count it once, to
example: $ A = {2,2,14,3 } $ Y $ B = {1,2,14,14,5 } $ the algorithm
I should go back 2. The problem is that I need to do this in $ O (m) $ hour.

My attempt was to create a matrix $ C $of size $ 2n $.
and increase all values ​​of $ A $ Y $ B $ by $ n $and count the values ​​of $ A $ I like it:
$ C (A (i)) = 1 $
that would take me $ O (m) $ time and $ O (1) $ Time to create the matrix.
then going $ B $ and counting how many $ 1 & # 39; s $ I am in $ C $.

So far it sounds good, however, I have no idea what there is $ C $ first and it could be that there is a $ 1 $ there already and that would increase the counter falsely, and initializing $ C $ it would take $ O (n) $ hour.

Any ideas?
Thanks ahead