#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
bool isPrime(long long a) {
  long long i;
  for (i = 2; i * i <= a; i++) {
    if (a % i == 0) {
      return 0;
    }
  }
  return (a != 1);
}
bool isPalindrom(const string &s, int l, int r) {
  for (int i = 0; i < (r - l + 1) / 2; i++) {
    if (s[l + i] != s[r - i]) {
      return 0;
    }
  }
  return 1;
}
template <class type1>
type1 gcd(type1 a, type1 b) {
  type1 t;
  while (b) {
    t = b;
    b = a % b;
    a = t;
  }
  return a;
}
long long positiveMod(long long v, long long md) {
  v = v % md;
  if (v < 0) {
    v += md;
  }
  return v;
}
int n, m;
vector<int> gr[5005];
int posA, posB, posC, posN;
int dist1[5005], dist2[5005], dist3[5005];
int distt[3][5005];
void bfs(int v, int arr[5005], int locked) {
  queue<int> q;
  for (int i = 1; i <= n; i++) {
    arr[i] = (1000000007ll);
  }
  arr[v] = 0;
  q.push(v);
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    for (auto it : gr[a]) {
      if (arr[it] == (1000000007ll) && it != locked) {
        arr[it] = arr[a] + 1;
        q.push(it);
      }
    }
  }
}
int getMin(int v, int arr[5005]) {
  int best = 0;
  for (int i = 1; i < gr[v].size(); i++) {
    if (arr[gr[v][i]] < arr[gr[v][best]]) {
      best = i;
    }
  }
  return gr[v][best];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int i, j, a, b;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  posA = 1;
  bfs(posA, dist1, -1);
  posB = posA;
  for (i = 1; i <= n; i++) {
    if (dist1[posB] < dist1[i]) {
      posB = i;
    }
  }
  bfs(posA, dist1, -1);
  bfs(posB, dist2, -1);
  posC = 1;
  for (i = 1; i <= n; i++) {
    if (min(dist1[posC], dist2[posC]) < min(dist1[i], dist2[i])) {
      posC = i;
    }
  }
  cout << posA << " " << posB << " " << posC << " "
       << "\n";
  cout.flush();
  cin >> posN;
  while (1) {
    for (auto it : gr[posA]) {
      if (it == posN) {
        posA = posN;
        cout << posA << " " << posB << " " << posC << " "
             << "\n";
        cout.flush();
        return 0;
      }
    }
    for (auto it : gr[posB]) {
      if (it == posN) {
        posB = posN;
        cout << posA << " " << posB << " " << posC << " "
             << "\n";
        cout.flush();
        return 0;
      }
    }
    for (auto it : gr[posC]) {
      if (it == posN) {
        posC = posN;
        cout << posA << " " << posB << " " << posC << " "
             << "\n";
        cout.flush();
        return 0;
      }
    }
    if (gr[posN].size() == 2) {
      bfs(gr[posN][0], dist1, posN);
      bfs(gr[posN][1], dist2, posN);
      a = max(dist1[posA], dist2[posB]);
      b = max(dist1[posB], dist2[posA]);
      if (a < b) {
        posA = getMin(posA, dist1);
        posB = getMin(posB, dist2);
      } else {
        posB = getMin(posB, dist1);
        posA = getMin(posA, dist2);
      }
      if (dist1[posC] < dist2[posC]) {
        posC = getMin(posC, dist1);
      } else {
        posC = getMin(posC, dist2);
      }
    } else {
      vector<int> bestPerm;
      int bestPermMax = (1000000007ll);
      vector<int> tempPerm;
      int tempPermMax;
      bestPerm.push_back(0);
      bestPerm.push_back(1);
      bestPerm.push_back(2);
      tempPerm.push_back(0);
      tempPerm.push_back(1);
      tempPerm.push_back(2);
      bfs(gr[posN][0], distt[0], posN);
      bfs(gr[posN][1], distt[1], posN);
      bfs(gr[posN][2], distt[2], posN);
      for (int step = 0; step < 6; step++) {
        tempPermMax = 0;
        tempPermMax += distt[tempPerm[0]][posA];
        tempPermMax += distt[tempPerm[1]][posB];
        tempPermMax += distt[tempPerm[2]][posC];
        tempPermMax +=
            max(max(distt[tempPerm[0]][posA], distt[tempPerm[1]][posB]),
                distt[tempPerm[2]][posC]);
        if (tempPermMax < bestPermMax) {
          bestPermMax = tempPermMax;
          bestPerm = tempPerm;
        }
        next_permutation(tempPerm.begin(), tempPerm.end());
      }
      posA = getMin(posA, distt[bestPerm[0]]);
      posB = getMin(posB, distt[bestPerm[1]]);
      posC = getMin(posC, distt[bestPerm[2]]);
    }
    cout << posA << " " << posB << " " << posC << " "
         << "\n";
    cout.flush();
    if (posA == posN || posB == posN || posC == posN) {
      break;
    }
    cin >> posN;
    if (posA == posN || posB == posN || posC == posN) {
      break;
    }
  }
  return 0;
}
