Chop off the matrix to get the desired sum
K (ngn/k), 39 bytes

{a@&amp;y=x{+//x*(&amp;/'b)&amp;\:&amp;/b:~x=y}/:a:,/x}


Try it online!

thanks @Adám for this explanation:

{…} function, x is M and y is S

 ,/x flatten M (these are the k candidates)

 a: assign to a

 x{…}/: apply the following function to each while using M as fixed left argument (x):

  x=y Boolean matrix indicating where elements of M equal the current k candidate

  ~ negate that 

  b: assign that to b

  &amp;/ AND reduction (finds columns without that k)

  (…)&amp;\: AND that with each of the following:

   &amp;/'b AND reduction of each (finds rows without that k)

  x* multiply M by that

  +// grand sum

 y= list of Booleans indicating where S equals those sums

 &amp; indices of Trues

 a@ use that to index into the elements (the k candidates)