#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

#define MaxN 1005

map < int, int > cnt, first;
int N, C, idx [ MaxN ];
int v [ MaxN ];

bool cmpf ( int i, int j ){
     if ( cnt[v[i]] != cnt[v[j]] ) return cnt[v[i]] > cnt[v[j]];
     if ( first[v[i]] != first[v[j]] ) return first[v[i]] < first[v[j]];
     return v[i] < v[j];
}     

int main ( void ){
    scanf("%d %d",&N,&C);
    
    for ( int i = 0; i < N; ++i ){
        scanf("%d",&v[i]);
        cnt[v[i]]++;
        if ( !first[v[i]] )
           first[v[i]] = i + 1;
        idx[i] = i;
        }
    
    sort ( idx, idx + N, cmpf );
        
    for ( int i = 0; i < N; ++i )
        printf("%d ",v[idx[i]]);
    printf("\n");  
    
    
    return 0;
}
