#include <bits/stdc++.h>
using namespace std;
typedef double f64; // long double is still the best
const int SPQR = 256, // Ave Imperator, morituri te salutant!
BMAX = 1 << 17;
const f64 EPS = 1e-7;
struct EDGE {
int v, w;
inline EDGE() { }
inline EDGE(int _v, int _w) {
v = _v;
w = _w; } };
char buck[BMAX];
vector<EDGE> g[SPQR];
valarray<f64> gs[SPQR];
inline bool eq(const f64 &a, const f64 &b) {
return abs(a - b) < EPS; }
inline char nextch(void) {
static int buff = BMAX;
if (buff == BMAX) {
buff = 0;
fread(buck, 1, BMAX, stdin); }
return buck[ buff++ ]; }
void get(int &arg) {
char ch;
arg = 0;
do {
ch = nextch(); }
while (ch < '0' || ch > '9');
do {
arg = arg * 10 + ch - '0';
ch = nextch(); }
while (ch >= '0' && ch <= '9'); }
int main(void) {
freopen("tunel.in", "r", stdin);
freopen("tunel.out", "w", stdout);
int n, m, u, v, w;
get(n), get(m);
for (int i = 1; i <= m; ++i) {
get(u), get(v), get(w);
if (u != n) g[u].emplace_back(v, w);
if (v != n) g[v].emplace_back(u, w); }
for (int i = 1; i < n; ++i) {
gs[i].resize(n + 2);
for (const auto &j: g[i]) {
gs[i][j.v]+= 1.0;
gs[i][n + 1]+= j.w; }
gs[i][i] = -int(g[i].size()); }
gs[n].resize(n + 2);
gs[n][n] = 1.0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (!eq(gs[j][i], 0.0))
swap(gs[i], gs[j]);
break; }
for (int j = 1; j <= n; ++j) if (i != j && !eq(gs[j][i], 0))
gs[j]-= gs[i] * (gs[j][i] / gs[i][i]); }
printf("%.4f\n", abs(gs[1][n + 1] / gs[1][1]));
return 0; }