1 #define mm(a) memset(a,0,sizeof(a));
 2 #define max(x,y) (x)>(y)?(x):(y)
 3 #define min(x,y) (x)<(y)?(x):(y)
 4 #define Fopen freopen("1.in","r",stdin); freopen("m.out","w",stdout);
 5 #define rep(i,a,b) for(int i=(a);i<=(b);i++)
 6 #define per(i,b,a) for(int i=(b);i>=(a);i--)
 7 #include<bits/stdc++.h>
 8 typedef long long ll;
 9 #define PII pair<ll,ll>
10 using namespace std;
11 const int INF=0x3f3f3f3f;
12 const int MAXN=(int)2e5 + 5;
13 const ll mod=1e9+7;
14 
15 struct node {
16     int x;
17     int val;
18     friend bool operator < (node a,node b) {
19         if(a.val!=b.val)return a.val<b.val;
20         return a.x>b.x;
21     }
22 };
23 string input,temp;
24 vector<int>v;
25 map<int,int>mp;
26 int n,dp[MAXN],m,k;
27 priority_queue<node>q;
28 int main() {
29     while (cin >> input) {
30         cin>>k;
31         mp.clear();
32         istringstream iss(input);
33         v.clear();
34         v.push_back(0);
35         while(!q.empty())q.pop();
36         while (getline(iss, temp, ',')) {
37             int x=atoi(temp.c_str());
38             v.push_back(x);
39             mp[x]++;
40         }
41         n=v.size()-1;
42         for(auto i:mp) {
43             q.push({i.first,i.second});
44         }
45         for(int i=1;i<=k;i++)printf("%d%c",q.top().x,i==k?'\n':','),q.pop();
46     }
47     return 0;
48 }