#include <bits/stdc++.h>
using namespace std;
vector<int> dijkstra(vector<vector<int>> &edges, int s) {
  vector<int> dist(edges.size(), 1e9);
  queue<int> pq;
  dist[s] = 0;
  pq.push(s);
  while (!pq.empty()) {
    auto u = pq.front();
    pq.pop();
    auto d = dist[u];
    if (d == dist[u])
      for (auto &e : edges[u])
        if (dist[e] > d + 1) {
          dist[e] = d + 1;
          pq.push(e);
        }
  }
  return dist;
}
void print_bees(array<int, 3> &bees) {
  for (auto x : bees) cout << 1 + x << ' ';
  cout << endl;
}
int read_pos() {
  int n;
  cin >> n;
  return n - 1;
}
bool done(array<int, 3> &bees, int N) {
  for (auto x : bees)
    if (x == N) return true;
  return false;
}
const array<array<int, 3>, 6> perms{{{{0, 1, 2}},
                                     {{0, 2, 1}},
                                     {{1, 0, 2}},
                                     {{1, 2, 0}},
                                     {{2, 0, 1}},
                                     {{2, 1, 0}}}};
void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  while (m--) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<vector<int>> dist(n);
  for (int i = 0; i < n; ++i) dist[i] = dijkstra(g, i);
  array<int, 3> bees;
  for (auto &x : bees) x = rand() % n;
  print_bees(bees);
  int N;
  while (true) {
    N = read_pos();
    if (done(bees, N)) return;
    for (int i = 0; i < 3; ++i) {
      if (dist[bees[i]][N] == 1) {
        bees[i] = N;
        print_bees(bees);
        cerr << "at dist 1\n";
        return;
      }
    }
    vector<int> nbs = g[N];
    assert(nbs.size() <= 3);
    while (nbs.size() < 3) nbs.push_back(nbs.back());
    int best_dist = -1;
    array<int, 3> best_bees;
    for (auto perm : perms) {
      array<int, 3> ps;
      for (int i = 0; i < 3; ++i) ps[i] = nbs[perm[i]];
      array<int, 3> newbees = bees;
      for (int i = 0; i < 3; ++i) {
        if (bees[i] == ps[i]) continue;
        for (auto d : g[bees[i]])
          if (dist[ps[i]][d] < dist[ps[i]][bees[i]]) {
            newbees[i] = d;
            break;
          }
      }
      int maxdist = 0;
      for (int i = 0; i < 3; ++i) maxdist = (maxdist + dist[ps[i]][newbees[i]]);
      if (best_dist == -1 or maxdist < best_dist) {
        best_dist = maxdist;
        best_bees = newbees;
      }
    }
    for (int i = 0; i < 3; ++i) assert(dist[bees[i]][best_bees[i]] <= 1);
    bees = best_bees;
    print_bees(bees);
    if (done(bees, N)) {
      cerr << "this shouldn't happen\n";
      return;
    }
  }
}
int main() {
  srand(123245);
  solve();
}
