#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int g[11][11];
int path[21];
int used[11][11];
int ans;
vector<int> anspath;
int n;
void solve(int now, int len, int dis) {
  //cout << string(len, ' ') << now << " "  << len << " " << dis << endl;
  bool f = 0;
  for (int i=1; i<=n; ++i) {
    if (g[now][i] != INF && !used[now][i]) {
      used[now][i] = 1;
      used[i][now] = 1;
      path[len] = i;
      solve(i, len+1, dis+g[now][i]);
      used[now][i] = 0;
      used[i][now] = 0;
      f = 1;
    }
  }
  if (!f) {
    if (ans < dis) {
      ans = dis;
      anspath = vector<int>(path, path+len);   
    }
  }
}

int main() {
  int m;
  while(cin >> n >> m, n||m) {
    REP(i,n+1) REP(j,n+1) g[i][j] = INF;
    REP(i, m) {
      int a,b,c;
      cin >> a>> b >> c;
      g[a][b] = c;
      g[b][a] = c;
    }
    REP(i,n) g[0][i+1] = 0;
    memset(used,0,sizeof(used));
    ans = 0;
    solve(0, 0, 0);
    cout << ans << endl;
    REP(i, anspath.size()) {
      if (i)  cout << " ";
      cout << anspath[i];
    }
    cout << endl;
  }
}