Consider each person as a node of a graph $G$ and exchanging gift/friendship as edges. As this graph doesn't have any cycle as if person $A_1$ is friend of $A_2$ , person $A_2$ is friend of person $A_3$, goes on and person $A_{i-1}$ is friend of person $A_i$ then person $A_1$ and person $A_i$ don't want to be friends. Thus $G$ is a forest . Each friend circle here is a connected component . Let each connected component has $V_i$ nodes, thus each connected component can have at most $V_i-1$ edges. Now sum them \^_^/