We are given 5040 balls in k different colors, where the number of balls of each color is the same. The balls are put into 2520 bags so that each bag contains two balls of different colors. Find the smallest k such that, however the balls are distributed into the bags, we can arrange the bags around a circle so that no two balls of the same color are in two neighboring bags.
1. **Claim**: The smallest number of colors \( k \) such that we can always arrange the bags around a circle so that no two balls of the same color are in two neighboring bags is \( \boxed{6} \).

2. **Proof that \( k = 5 \) fails**:
    - Label the colors \( A, B, C, D, E \).
    - Each color has \( \frac{5040}{5} = 1008 \) balls.
    - Pair the balls such that:
        - \( AB \) pairs: 1008 bags
        - \( CD, DE, EC \) pairs: 504 bags each
    - Total bags: \( 1008 + 3 \times 504 = 2520 \).
    - Try to arrange these bags in a circle:
        - Start with \( AB \).
        - Next bag must be \( CD, DE, \) or \( EC \).
        - After this, the next bag must be \( AB \) again to avoid repeating colors.
        - This implies every second bag must be \( AB \), requiring \( 1260 \) \( AB \) bags, which is more than the available \( 1008 \) \( AB \) bags.
    - Contradiction: \( k = 5 \) is not sufficient.

3. **Proof that \( k = 6 \) works**:
    - Label the colors \( A, B, C, D, E, F \).
    - Use induction on \( k \):
        - **Base cases**:
            - \( k = 1 \): Trivial, as each bag has different colors.
            - \( k = 2 \): Handle by casework on cycle lengths.
        - **Inductive step**:
            - Assume true for \( k-1 \) and \( k-2 \).
            - Prove for \( k \).

4. **Lemma**: For any grouping of balls, at least one of the following is true:
    - i) Three bags with a ball of every color.
    - ii) Three bags with all combinations of three colors, and three more bags with all combinations of the remaining three colors.
    - **Proof of Lemma**:
        - Assume otherwise.
        - Call a combination relevant if there exists a bag with that combination.
        - Assume \( AB \) and \( CD \) are relevant.
        - \( EF \) cannot be relevant (else i) is true).
        - At least two combinations involving \( E \) and \( F \) each must be relevant.
        - Suppose \( EA \) is relevant.
        - \( FB \) cannot be relevant (else i) is true).
        - \( EB \) relevant implies \( FA \) cannot be relevant.
        - \( FC \) and \( FD \) must be relevant.
        - \( BD \) cannot be relevant (else i) is true).
        - Relevant pairs must include \( A \) or \( C \), contradicting the number of balls.
        - Therefore, the lemma is true.

5. **Inductive step**:
    - **Case i)**:
        - Assume three bags \( AB, CD, EF \).
        - Arrange all but these three bags in a circle.
        - Place \( AB \) next to a bag with neither \( A \) nor \( B \).
        - Place \( CD \) or \( EF \) next to a bag with \( A \) or \( B \).
        - Place the remaining bag in between.
    - **Case ii)**:
        - Assume three bags \( AB, BC, CA \) and \( DE, EF, FD \).
        - Arrange all but these six bags in a circle.
        - Place \( AB \) next to a bag with neither \( A \) nor \( B \).
        - Place \( DE, EF, \) or \( FD \) next to a bag with \( A \) or \( B \).
        - Alternate remaining bags from group one and group two.

6. **Conclusion**:
    - In either case, we can arrange the bags in a circle such that no two balls of the same color are in neighboring bags.