Berachos, Chapter 3, Mishnah 1. In the previous chapter we learned the principle that someone who is preoccupied and involved in one mitzvah is exempt from another mitzvah. Our mishnah, and several of the mishnayos that follow it, deal at length with this rule that one who is engaged in a mitzvah is exempt from the mitzvah.
The Law of the Onen:
The mishnah discusses someone whose family member has passed away and for whom he is obligated to mourn. During the period after the death, while the deceased is "mutal lefanav" - literally lying before him, meaning he has not yet been buried - he is exempt from Shema, from the Shemoneh Esreh prayer and from putting on tefillin. And in the Gemara's version of the mishnah they add: he is exempt even "mikol hamitzvos ha'amuros baTorah" - from all the mitzvos stated in the Torah.
This is the law known as an 'onen': one whose relative has not yet been buried. Since he is generally occupied with burying the deceased, he is exempt from all the mitzvos - he does not recite berachos and he does not perform mitzvos at all.
Those Who Accompany the Deceased:
From here the mishnah moves on to discuss the others who take part in the funeral and in escorting the deceased. Two categories of people are listed here:
"nosei hamitah vechilufeihen" - those who actually carry the bier, and those who take turns with them. This is how they would transfer the bier from one group to the next.
"eilu shelifnei hamitah ve'eilu she'achar hamitah" - those who walk in the funeral procession in front of the bier and those who walk behind it.
In both cases everything depends on one question: whoever is needed by the bier - meaning that he is going to actually carry it and be directly involved in that - is exempt from Shema. And whoever is not needed by the bier, and is merely escorting it, is obligated in Shema.
The reason for this: Shema is a mitzvah that can be fulfilled while walking, and even the very first verse, which requires concentration, can be said by standing still for a moment. For this reason it is possible for those escorting the deceased, who are not actually carrying him, to fulfill the mitzvah of Shema.
Both Groups Are Exempt from Prayer:
But "eilu ve'eilu" - both these and those, both those who are needed by the bier and are going to actually carry it, and those who are not going to carry it but are merely escorting it - are exempt from prayer, from Shema and from the Shemoneh Esreh prayer. This is because they cannot be fulfilled while walking, since they require standing still and concentration.
In summary: In this mishnah we learned the law of the onen - that as long as his deceased relative lies before him and has not been buried, he is exempt from Shema, from prayer, from tefillin and from all the mitzvos stated in the Torah, because he is preoccupied with burying his dead. We also learned the law of those who escort the deceased: the bearers of the bier and those who take turns with them, and those who walk before the bier and after it - those whom the bier needs are exempt, and those whom the bier does not need are obligated in Shema, which can be fulfilled even while walking; and both groups are exempt from prayer, which requires standing still and concentration.