#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

struct ClassInfo
{
    ClassInfo(): size(0), lastChange(0){ }
    ClassInfo(size_t size, size_t lastChange): size(size), lastChange(lastChange){ }
    size_t size;
    size_t lastChange;
};

typedef std::pair<size_t, size_t> ClassUser;
typedef std::vector<ClassUser> ClassUsers;

class UserClassificator
{
public:
    UserClassificator(size_t numUsers)
        :numPerformance_(0),
         performanceAppear_(numUsers, 0)
    {
        for(size_t i = 0; i < numUsers; ++i) {
            positions_.push_back(
                users_.insert(make_pair(std::vector<size_t>(), i))
            );
        }
    }

    void addPerformance(const std::vector<size_t>& actors)
    {
        numPerformance_++;
        for(size_t i = 0; i < actors.size(); ++i) {
            size_t actor = actors[i];
            Users::iterator it = positions_[actor];
            std::vector<size_t> perf = it->first;
            perf.push_back(numPerformance_);
            users_.erase(it);
            positions_[actor] = users_.insert(make_pair(perf, actor));
        }
        for(size_t i = 0; i < performanceAppear_.size(); ++i) {
            size_t& res = performanceAppear_[i];
            if (res == 0 && users_.count(positions_[i]->first) == 1) {
                res = numPerformance_;
            }
        }
    }

    size_t performanceAppear(size_t user) const
    {
        return performanceAppear_[user];
    }

private:
    size_t numPerformance_;
    std::vector<size_t> performanceAppear_;
    typedef std::multimap<std::vector<size_t>, size_t> Users;
    std::vector<Users::iterator> positions_;
    Users users_;
};

int main () {
    freopen("theatre.in", "r", stdin);
    freopen("theatre.out", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    size_t n, m;
    std::cin >> n >> m;
    UserClassificator classificator(n);
    for(size_t step = 0; step < m; ++step) {
        size_t k;
        std::cin >> k;
        std::vector<size_t> users;
        users.reserve(k);
        for(size_t t = 0; t < k; ++t) {
            size_t user;
            std::cin >> user;
            users.push_back(user - 1);
        }
        classificator.addPerformance(users);
    }
    for(size_t i = 0; i < n; ++i) {
        size_t res = classificator.performanceAppear(i);
        if (i > 0) std::cout << " ";
        std::cout << res;
    }
    std::cout << std::endl;
    return 0;
}

