5. The exam consists of $N \geqslant 3000$ questions. Each of the 31 students has learned exactly 3000 of them, and every question is known by at least 29 students. Before the exam, the teacher openly laid out all the question cards in a circle. He asked the students to point to one of the questions and explained that he would give this question to the first student in alphabetical order, the next question in the clockwise direction to the second student, the next to the third, and so on (one question to each student). However, the students were unable to point to a card such that each of them received a question they knew. For what smallest $N$ could this have happened?
Answer: $N=3100$.

Each student does not know $N-3000$ questions and thus can mentally mark exactly that many cards which do not suit them as the initial one. Together, they can indicate no more than $31(N-3000)$ different cards. If $31(N-3000)<N$, then the students can indicate a card that suits everyone. This inequality is equivalent to $30 N<31 \cdot 3000$, i.e., $N<3100$. Therefore, when $N<3100$, the situation described in the problem is impossible.

Let $N=3100$. We describe a situation (one of many) that satisfies the problem's conditions. Number the cards from 1 to 31000. Let the first student know all questions except for the 100 cards whose numbers give a remainder of 1 when divided by 31. The second student knows all cards except those with a remainder of 3, and thus his initial cards are those with a remainder of 2. The third student knows all cards except those with a remainder of 5, and thus forbids initial cards with a remainder of 3. In general, the $k$-th student does not know questions with a remainder of $2 k-1$ and thus forbids initial cards with a remainder of $k$. Thus, all cards are forbidden. Each student knows exactly 3000 questions, and each question is known by everyone except one student.