#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int n, m, a[2010], b[2010];
vector<pair<int, int>> G[110];
bool vis[2010];
void dfs(int i, int &t) {
  for (const auto &e : G[i]) {
    if (vis[e.second]) continue;
    vis[e.second] = true;
    dfs(e.first, t);
  }
  b[t--] = i;
}
void solve(int i) {
  for (int k = 0; k < (int)G[a[i]].size(); ++k) {
    if (G[a[i]][k].first <= a[i + 1]) continue;
    auto tmp = G[a[i]][k];
    G[a[i]].erase(G[a[i]].begin() + k);
    G[a[i]].insert(G[a[i]].begin(), tmp);
    copy_n(a, i + 1, b);
    fill_n(vis, m, 0);
    int t = m;
    dfs(a[i], t);
    G[a[i]].erase(G[a[i]].begin());
    G[a[i]].insert(G[a[i]].begin() + k, tmp);
    bool ck = false;
    for (int j = 0; j <= m; ++j) {
      if (b[j] != a[j]) {
        ck = b[j] > a[j];
        break;
      }
    }
    if (!ck) continue;
    for (int j = 0; j <= m; ++j) cout << b[j] << " \n"[j == m];
    cout.flush();
    exit(0);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  for (int i = 0; i <= m; ++i) cin >> a[i];
  for (int i = m - 1; i >= 0; --i) {
    G[a[i]].emplace_back(a[i + 1], i);
    sort(G[a[i]].begin(), G[a[i]].end());
    G[a[i + 1]].emplace_back(a[i], i);
    sort(G[a[i + 1]].begin(), G[a[i + 1]].end());
    solve(i);
  }
  cout << "No solution\n";
  return 0;
}
