Help me in solving BLDST problem

My issue

My code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int minimumBoxes(int N, int M, vector<int>& ballColors) {
    int totalColors = 0;
    int totalBalls = 0;

    for (int i = 0; i < M; i++) {
        totalColors += (ballColors[i] > 0);
        totalBalls += ballColors[i];
    }

    return (totalBalls >= M && totalColors >= M) ? M : -1;
}

int main() {
    int T;
    cin >> T;

    while (T--) {
        int N, M;
        cin >> N >> M;

        vector<int> ballColors(M);
        for (int i = 0; i < M; i++) {
            cin >> ballColors[i];
        }

        int minBoxes = minimumBoxes(N, M, ballColors);
        cout << minBoxes << endl;
    }

    return 0;
}

Problem Link: BLDST Problem - CodeChef

@nitap620243
the logic is not right
your codes says the answer is only M or -1
which is absolutely wrong it can vary.
like for ex :-
1
5 3
5 2 2
the answer would be 0
1 2
1 2
1 3
1 3
1
see the above placement none of the box has m balls;