After you computed lst
list, you don't need to find matching elements in it. The only thing you need to do is to traverse the list to find the element with maximum tuple second value.
fun findMax l =
let fun find (nil, acc) = acc
| find ((value, count)::xs, (acc_value, acc_count)) =
if count > acc_count then find (xs, (value, count))
else if value = acc_value then (acc_value, acc_count)
else find (xs, (acc_value, acc_count))
in find (l, (0, 0)) end;
findMax lst;
val it = (1, 5): int * int
However, this solution has O(n2) complexity. Alternatively, you can sort elements first in O(n * log n) time, and then return the first element (or several ones) from the list with maximum number of occurrences.