#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5;
struct Node {
  int a, id;
} a[N + 5];
int n, k;
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
vector<int> maxn, now;
int ans[N + 5], len;
bool vis[N + 5];
int main() {
  n = read();
  k = read();
  for (int i = 1; i <= n; i++) {
    a[i].a = read();
    a[i].id = i;
  }
  srand(time(NULL));
  int num;
  while (1) {
    random_shuffle(a + 1, a + 1 + n);
    now.clear();
    now.push_back(a[1].id);
    for (int i = 2; i <= n; i++)
      if (gcd(a[i].a, a[1].a) == 1) now.push_back(a[i].id);
    len = 0;
    ans[++len] = a[1].id;
    num = a[1].a;
    for (int i = 2; i <= n; i++)
      if (gcd(a[i].a, num) != 1) {
        ans[++len] = a[i].id;
        num = gcd(a[i].a, num);
      }
    if (len >= k) {
      for (int i = 1; i <= k; i++) printf("%d ", ans[i]);
      puts("");
      return 0;
    }
    memset(vis, 0, sizeof vis);
    len = 0;
    for (int i = 0; i < (int)now.size(); i++) {
      ans[++len] = now[i];
      vis[now[i]] = 1;
    }
    if (!maxn.empty() && gcd(a[maxn[0]].a, a[now[0]].a) == 1)
      for (int i = 0; i < (int)maxn.size(); i++)
        if (!vis[maxn[i]]) {
          vis[maxn[i]] = 1;
          ans[++len] = maxn[i];
        }
    if (len >= k) {
      for (int i = 1; i <= k; i++) printf("%d ", ans[i]);
      puts("");
      return 0;
    }
    if ((int)now.size() > (int)maxn.size()) maxn = now;
  }
  return 0;
}
