7232 {
7233 int n;
7234 int m;
7235 cin >> n >> m;
7236 vector<unordered_map<int, int>> g(n + 1);
7237 vector reachable(n + 1, false);
7238 vector shortest(n + 1, 0x3f3f3f);
7239 for(int i = 0; i < m; i++) {
7240 int x;
7241 int y;
7242 int z;
7243 cin >> x >> y >> z;
7244 if(g[x][y] == 0) {
7245 g[x][y] = z;
7246 } else {
7247 g[x][y] = min(g[x][y], z);
7248 }
7249 }
7250 queue<int> q;
7251 unordered_set<int> us;
7252 us.insert(1);
7253 q.push(1);
7254 shortest[1] = 0;
7255 reachable[1] = true;
7256 while(!q.empty()) {
7257 int node = q.front();
7258 q.pop();
7259 us.erase(node);
7260 for(auto [next_node, d]: g[node]) {
7261 reachable[next_node] = true;
7262 if(shortest[next_node] > shortest[node] + d) {
7263 shortest[next_node] = shortest[node] + d;
7264 if(!us.contains(next_node)) {
7265 q.push(next_node);
7266 us.insert(next_node);
7267 }
7268 }
7269 }
7270 }
7271 if(!reachable[n]) {
7272 cout << "impossible";
7273 } else {
7274 cout << shortest[n];
7275 }
7276 return 0;
7277 }