In set $M$, at most three numbers can give the same remainder when divided by $m$. Indeed, $m$ is a prime number in both given cases, so the sum of fewer than $m$ numbers, which give the same remainder when divided by $m$, is not divisible by $m$.

If $m=5$, then the number of possible remainders is four, so $M$ can consist of at most $4 \cdot 3 = 12$ numbers. We will show that the conditions are met for the twelve-element set $M=\{1,2,3,4,6,7,8,9,11,12,13,14\}$, which means that the sought number in case a) is 12.

Let $a, b, c$, and $d$ be elements of $M$. Since every non-zero remainder appears exactly three times in $M$, among these four numbers, there are two - say $b$ and $c$ - which give different remainders when divided by 5. Consider the following five numbers:

$$
a ; \quad a+b ; \quad a+c ; \quad a+b+c ; \quad a+b+c+d
$$

If any of these is divisible by 5, we are done. If not, then there are two among them that give the same remainder when divided by 5. These two cannot be $a+b$ and $a+c$, as per our assumption, $b$ and $c$ give different remainders when divided by 5. Thus, the difference divisible by 5 is the sum of two or three of $a, b, c$, and $d$.

If $m=7$, then the number of possible non-zero remainders is 6, so according to the above reasoning, $M$ can have at most $6 \cdot 3 = 18$ elements. However, this is not achievable, and the sought value is 8. First, we provide an 8-element set that meets the conditions, which is $M=\{1,2,3,4,5,6,8,13\}$. We claim that the conditions are met for this set. Group the elements of $M$ into pairs: $(1,6),(2,5),(3,4),(8,13)$. If among the four selected elements of $M$, both members of a pair are present, we are done. We need to examine the case where each of the four selected numbers comes from a different pair. The following table shows that in this case, we always find a sum divisible by 7:

| $(1,6)$ | $(8,13)$ | $(2,5)$ | $(3,4)$ | Sum divisible by 7 |
| :---: | :---: | :---: | :---: | :---: |
| 1 | 13 | any | any | $1+13$ |
| 1 | 8 | 5 | any | $1+8+5$ |
| 1 | 8 | 2 | 3 | $1+8+2+3$ |
| 1 | 8 | 2 | 4 | $1+2+4$ |
| 6 | 8 | any | any | $6+8$ |
| 6 | 13 | 2 | any | $6+13+2$ |
| 6 | 13 | 5 | 4 | $6+13+5+4$ |
| 6 | 13 | 5 | 3 | $6+5+3$ |

Secondly, we claim that $M$ cannot have more than eight elements. If $M$ has at least nine elements, then since at most six different remainders can occur, and each can occur at most three times, there are $a_1$ and $a_2$ that give the same remainder $a$, and there are $b_1$ and $b_2$ that give the same remainder $b$ different from $a$ when divided by 7 $(1 \leqq a, b \leqq 6)$.

For the quadruple $\left(a_{1}, a_{2}, b_{1}, b_{2}\right)$, the condition can only be satisfied if one of the sums $a+b, 2a+b, 2b+a$ is divisible by 7, or the product of these sums is divisible by 7. Since the product of these three numbers is

$$
(a+b)(2a+b)(2b+a)=2\left(a^{3}+b^{3}\right)+7\left(a^{2}b+b^{2}a\right)
$$

it follows that $a^{3}+b^{3}$ is divisible by 7. A number not divisible by 7 gives a remainder of 1 or 6 when divided by 7, so from this, we get that one of $a^{3}$ and $b^{3}$ gives a remainder of 1, and the other gives a remainder of 6 when divided by 7.

If $M$ has at least nine elements, then there must be $c_1$ and $c_2$ that give the same remainder $c$ different from $a$ and $b$ when divided by 7. If neither of the remainders $a$ and $b$ appears more than twice, then the other five numbers can give at most four different remainders. If, for example, $a$ appears three times, then denoting one of the other six numbers by $d$, one of $a+d, 2a+d, 3a+d$ must be divisible by 7, so the six numbers can give at most three different remainders, and thus there are two remainders different from $a$ that appear at least twice.

If, however, the remainders $a, b$, and $c$ each appear at least twice, then in addition to $a^{3}+b^{3}$, $a^{3}+c^{3}$ and $b^{3}+c^{3}$ are also divisible by 7. This, however, is not possible, since for any two of $a^{3}, b^{3}$, and $c^{3}$, one must give a remainder of 1 and the other a remainder of 6 when divided by 7. Therefore, $M$ cannot have more than eight elements.

Thus, the maximum number of elements in a set $M$ that satisfies the conditions of the problem is 12 in case a) and 8 in case b).
We know that none of the elements in the set $M$ of natural numbers is divisible by $m$, and on the other hand, among any four elements of $M$, there are some whose sum is divisible by $m$.

What is the maximum number of elements that the set $M$ can have if a) $m=5$, b) $m=7$?