#include <bits/stdc++.h>
using namespace std;
using iv = vector<int>;
const int N = 5e3 + 1;
int dp[N][N];
iv g[N];
queue<int> q;
struct bees {
  int a, b, c;
  bees(int A = 0, int B = 0, int C = 0) : a(A), b(B), c(C) {}
  bool operator<(const bees& x) const {
    if (a != x.a) return a < x.a;
    if (b != x.b) return b < x.b;
    if (c != x.c) return c < x.c;
    return false;
  }
  bees& sort() {
    int x[] = {a, b, c};
    std::sort(x, x + 3), a = x[0], b = x[1], c = x[2];
    return *this;
  }
  bees sorted(int p) const { return bees(dp[a][p], dp[b][p], dp[c][p]).sort(); }
  bees f(int p) const {
    bees h;
    for (auto i : g[p]) h = max(h, sorted(i));
    return h;
  }
  bees next_move(const int p) {
    bees h, u, ans = *this, m = f(p);
    for (auto x0 : g[a])
      for (auto x1 : g[b])
        if (x1 != x0)
          for (auto x2 : g[c])
            if (x2 != x0 and x2 != x1)
              if (u = bees(x0, x1, x2), h = u.f(p), h < m) m = h, ans = u;
    return ans;
  }
  void write() const { cout << a << ' ' << b << ' ' << c << endl; }
  bool done(int u) const { return a == u or b == u or c == u; }
};
int main() {
  int m, n, p, u, v;
  bees b(1, 2, 3);
  ios_base::sync_with_stdio(0), cin.tie(0), memset(dp, -1, sizeof dp);
  for (cin >> n >> m; m--; g[u].push_back(v), g[v].push_back(u)) cin >> u >> v;
  for (u = 1; u <= n; ++u)
    for (dp[u][u] = 0, q.push(u); not q.empty(); q.pop())
      for (auto v : g[p = q.front()])
        if (dp[u][v] == -1) dp[u][v] = dp[u][p] + 1, q.push(v);
  for (u = 1; u <= n; ++u) g[u].push_back(u);
  for (b.write(), cin >> p; not b.done(p); cin >> p)
    if (b = b.next_move(p), b.write(), b.done(p)) break;
}
