#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MN = 5003;
int n, m;
vector<int> g[MN];
int dist[MN][MN];
void pre() {
  for (int x = 1; x <= n; ++x) {
    queue<int> q;
    q.push(x);
    dist[x][x] = 1;
    while (!q.empty()) {
      int p = q.front();
      q.pop();
      for (auto i : g[p]) {
        if (!dist[x][i]) {
          q.push(i);
          dist[x][i] = dist[x][p] + 1;
        }
      }
    }
    for (int y = 1; y <= n; ++y) --dist[x][y];
  }
}
array<int, 3> dd(int p, int a, int b, int c) {
  array<int, 3> ans = {dist[a][p], dist[b][p], dist[c][p]};
  sort(ans.begin(), ans.end());
  return ans;
}
array<int, 3> check(int p, int a, int b, int c) {
  array<int, 3> ans = {0, 0, 0};
  for (int i : g[p]) {
    ans = max(ans, dd(i, a, b, c));
  }
  return ans;
}
array<int, 3> get_move(int p, int a, int b, int c) {
  array<int, 3> ans = {a, b, c};
  array<int, 3> mi = check(p, a, b, c);
  for (auto na : g[a]) {
    for (auto nb : g[b]) {
      for (auto nc : g[c]) {
        if (na == nb || nb == nc || nc == na) continue;
        auto t = check(p, na, nb, nc);
        if (t < mi) {
          mi = t;
          ans = {na, nb, nc};
        }
      }
    }
  }
  return ans;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  pre();
  for (int i = 1; i <= n; ++i) g[i].push_back(i);
  int p, a = 1, b = 2, c = 3;
  cout << a << ' ' << b << ' ' << c << endl;
  while (1) {
    cin >> p;
    if (p == a || p == b || p == c) break;
    array<int, 3> t = get_move(p, a, b, c);
    a = t[0];
    b = t[1];
    c = t[2];
    cout << a << ' ' << b << ' ' << c << endl;
    if (a == p || b == p || c == p) break;
  }
  return 0;
}
