import sys
from heapq import heappop, heappush

input = sys.stdin.readline

def dijkstra(graph, start=0):
    n = len(graph)
    dist, parents = [float('inf')] * n, [-1] * n
    dist[start] = 0.0

    queue = [(0.0, start)]
    while queue:
        path_len, v = heappop(queue)
        if path_len == dist[v]:
            for (w, edge_len) in graph[v]:
                if edge_len + path_len < dist[w]:
                    dist[w], parents[w] = edge_len + path_len, v
                    heappush(queue, (edge_len + path_len, w))

    return dist, parents

def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    for i in range(m):
        _a, _b, _w = input().split()
        a, b, w = int(_a) - 1, int(_b) - 1, float(_w)
        graph[b].append((b, w))
        graph[a].append((a, w))

    _, parents = dijkstra(graph)
    if parents[n - 1] == -1:
        print(-1)
    else:
        res, parent = [], n - 1
        while parent != parents[0]:
            res.append(parent + 1)
            parent = parents[parent]
        res.reverse()
        print(*res)

BUFSIZE = 8192

main()


import sys
from heapq import heappop, heappush

input = sys.stdin.readline

def dijkstra(graph, start=0):
    n = len(graph)
    dist, parents = [float('inf')] * n, [-1] * n
    dist[start] = 0.0

    queue = [(0.0, start)]
    while queue:
        path_len, v = heappop(queue)
        if path_len == dist[v]:
            for (w, edge_len) in graph[v]:
                if edge_len + path_len < dist[w]:
                    dist[w], parents[w] = edge_len + path_len, v
                    heappush(queue, (edge_len + path_len, w))

    return dist, parents

def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    for i in range(m):
        _a, _b, _w = input().split()
        a, b, w = int(_a) - 1, int(_b) - 1, float(_w)
        graph[a].append((b, w))
        graph[b].append((a, w))

    _, parents = dijkstra(graph)
    if parents[n - 1] == 1:
        print(-1)
    else:
        res, parent = [], n - 1
        while parent != parents[0]:
            res.append(parent + 1)
            parent = parents[parent]
        res.reverse()
        print(*res)

BUFSIZE = 8192

main()


#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from heapq import heappop, heappush
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def dijkstra(graph, start=0):
    n = len(graph)
    dist, parents = [float('inf')] * n, [-1] * n
    dist[start] = 0.0

    queue = [(0.0, start)]
    while queue:
        path_len, v = heappop(queue)
        if path_len == dist[v]:
            for (w, edge_len) in graph[v]:
                if edge_len + path_len < dist[w]:
                    dist[w], parents[w] = edge_len + path_len, v
                    heappush(queue, (edge_len + path_len, w))

    return dist, parents

def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    for i in range(m):
        _a, _b, _w = input().split()
        a, b, w = int(_a) - 1, int(_b) - 1, float(_w)
        graph[a].append((b, w))
        graph[b].append((a, w))

    _, parents = dijkstra(graph)
    if parents[n - 1] == -1:
        print(-1)
    else:
        res, parent = [], n - 1
        while parent != parents[0]:
            res.append(parent + 1)
            parent = parents[parent]
        res.reverse()
        print(*res)

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


from sys import stdin
import heapq

def main():
    n, m = map(int, stdin.readline().split())
    adj = [[] for _ in range(n + 1)]
    for _ in range(m):
        x, y, w = map(int, stdin.readline().split())
        if x == y:
            continue
        adj[x].append((y, w))
        adj[y].append((x, w))
    max_val = 10 ** 10 + 1
    dist = [max_val] * (n + 1)
    dist[1] = 0
    q = []
    heapq.heappush(q, (0, 1))
    process = [False] * (n + 1)
    prev = [i for i in range(n + 1)]
    while q:
        cd, cv = heapq.heappop(q)
        if cd != dist[cv]:
            continue
        for p in adj[cv]:
            nb = p[0]
            w = p[1]
            if dist[cv] + w < dist[nb]:
                dist[nb] = dist[cv] + w
                prev[nb] = cv
                heapq.heappush(q, (dist[nb], nb))
    if dist[n] == max_val:
        print(-1)
    else:
        ans = []
        cv = n
        while prev[cv] != cv:
            ans.append(cv)
            cv = prev[cv]
        ans.append(1)
        ans.reverse()
        print(*ans)

if __name__ == '__main__':
    main()


from sys import stdin
import heapq

def main():
    n, m = map(int, stdin.readline().split())
    adj = [[] for _ in range(n + 1)]
    for _ in range(m):
        x, y, w = map(int, stdin.readline().split())
        if x == y:
            continue
        adj[x].append((y, w))
        adj[y].append((x, w))
    max_val = 10 ** 18
    dist = [max_val] * (n + 1)
    dist[1] = 0
    q = []
    heapq.heappush(q, (0, 1))
    process = [False] * (n + 1)
    prev = [i for i in range(n + 1)]
    while q:
        cd, cv = heapq.heappop(q)
        if cd != dist[cv]:
            continue
        for p in adj[cv]:
            nb = p[0]
            w = p[1]
            if dist[cv] + w < dist[nb]:
                dist[nb] = dist[cv] + w
                prev[nb] = cv
                heapq.heappush(q, (dist[nb], nb))
    if dist[n] == max_val:
        print(-1)
    else:
        ans = []
        cv = n
        while prev[cv] != cv:
            ans.append(cv)
            cv = prev[cv]
        ans.append(1)
        ans.reverse()
        print(*ans)

if __name__ == '__main__':
    main()


from heapq import heappush,heappop,heapify
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for j in range(m):
	a,b,w=map(int,input().split())
	graph[a-1].append([b-1,w])
	graph[b-1].append([a-1,w])
inf=1000001
dist={i:inf for i in range(1,n)}
dist[0]=0
prec={}
q=[(0,0)]
while q:
	d,node=heappop(q)
	for adj,w in graph[node]:
		if d+w<dist[adj]:
			heappush(q,(d+w,adj))
			dist[adj]=d+w
			prec[adj]=node

if dist[n-1]==inf:
	print(-1)
else:
	i=n-1
	ans=[]
	while i!=0:
		ans.append(i+1)
		i=prec[i]
	ans.append(1)
	print(*ans[::-1])


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

from heapq import heappush,heappop,heapify
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for j in range(m):
	a,b,w=map(int,input().split())
	graph[a-1].append([b-1,w])
	graph[b-1].append([a-1,w])
inf=1000001
dist={i:inf for i in range(1,n)}
dist[0]=0
prec={}
q=[(0,0)]
while q:
	d,node=heappop(q)
	for adj,w in graph[node]:
		if d+w<dist[adj]:
			heappush(q,(d+w,adj))
			dist[adj]=d+w
			prec[adj]=node
i=n-1
t=True
ans=[i+1]
while i:
	if i in prec:
		ans.append(prec[i]+1)
	else:
		t=False
		break
	i=prec[i]

if t:
	print(*ans[::-1])
else:
	print(-1)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

from heapq import heappush,heappop,heapify
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for j in range(m):
	a,b,w=map(int,input().split())
	graph[a-1].append([b-1,w])
	graph[b-1].append([a-1,w])
inf=1000001
dist={i:inf for i in range(1,n)}
dist[0]=0
prec={}
q=[(0,0)]
while q:
	d,node=heappop(q)
	for adj,w in graph[node]:
		if d+w<dist[adj]:
			heappush(q,(d+w,adj))
			dist[adj]=d+w
			prec[adj]=node

if dist[n-1]==inf:
	print(-1)
else:
	i=n-1
	ans=[]
	while i!=0:
		ans.append(i+1)
		i=prec[i]
	ans.append(1)
	print(*ans[::-1])


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'
from heapq import heappush,heappop,heapify
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for j in range(m):
	a,b,w=map(int,input().split())
	graph[a-1].append([b-1,w])
	graph[b-1].append([a-1,w])
inf=float("inf")
dist={i:inf for i in range(1,n)}
dist[0]=0
prec={}
q=[(0,0)]
while q:
	d,node=heappop(q)
	for adj,w in graph[node]:
		if d+w<dist[adj]:
			heappush(q,(d+w,adj))
			dist[adj]=d+w
			prec[adj]=node
i=n-1
t=True
ans=[i+1]
while i:
	if i in prec:
		ans.append(prec[i]+1)
	else:
		t=False
		break
	i=prec[i]

if t:
	print(*ans[::-1])
else:
	print(-1)


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

from heapq import heappush,heappop,heapify
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for j in range(m):
	a,b,w=map(int,input().split())
	graph[a-1].append([b-1,w])
	graph[b-1].append([a-1,w])
inf=1000001
dist={i:inf for i in range(1,n)}
dist[0]=0
prec={}
q=[(0,0)]
while q:
	d,node=heappop(q)
	for adj,w in graph[node]:
		if d+w<=dist[adj]:
			heappush(q,(d+w,adj))
			dist[adj]=d+w
			prec[adj]=node

if dist[n-1]==inf:
	print(-1)
else:
	i=n-1
	ans=[]
	while i!=0:
		ans.append(i+1)
		i=prec[i]
	ans.append(1)
	print(*ans[::-1])


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange
BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

from heapq import heappush,heappop,heapify
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for j in range(m):
	a,b,w=map(int,input().split())
	graph[a-1].append([b-1,w])
	graph[b-1].append([a-1,w])
inf=1000001
dist={i:inf for i in range(1,n)}
dist[0]=0
prec={}
q=[(0,0)]
while q:
	d,node=heappop(q)
	for adj,w in graph[node]:
		if d+w<dist[adj]:
			heappush(q,(d+w,adj))
			dist[adj]=d+w
			prec[adj]=node
i=n-1
ans=[i+1]
while i:
	ans.append(prec[i]+1)
	i=prec[i]
if ans[-1]==1:
	print(*ans[::-1])
else:print(-1)


import heapq
import atexit
import io
import sys

_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def dijkstra(adj, source, target):
    INF = ((1 << 63) - 1) // 2
    pred = {x: x for x in adj}
    dist = {x: INF for x in adj}
    dist[source] = 0
    PQ = []
    heapq.heappush(PQ, [dist[source], source])

    while (PQ):
        u = heapq.heappop(PQ)
        u_dist = u[0]
        u_id = u[1]
        if u_dist == dist[u_id]:
            for v in adj[u_id]:
                v_id = v[0]
                w_uv = v[1]
                if dist[u_id] + w_uv < dist[v_id]:
                    dist[v_id] = dist[u_id] + w_uv
                    heapq.heappush(PQ, [dist[v_id], v_id])
                    pred[v_id] = u_id

    if target not in dist or dist[target] == INF:
        print("-1")
        exit(0)
    else:
        st = []
        node = target
        while True:
            st.append(str(node))
            if node == pred[node]:
                break
            node = pred[node]
        return st[::-1]

n, m = map(int, input().split())
graph = dict()

for i in range(m):
    a, b, w = map(int, input().split())
    if a in graph:
        graph[a].append((b, w))
    else:
        graph[a] = [(b, w)]
    if b in graph:
        graph[b].append((a, w))
    else:
        graph[b] = [(a, w)]

print(*map(int, dijkstra(graph, 1, n)))


def dijkstra(graph, src, dest, visited=[], distances={}, predecessors={}):
    if src not in graph:
        raise TypeError('The root of the shortest path tree cannot be found')
    if dest not in graph:
        raise TypeError('The shortest path cannot be found')
    if src == dest:
        path = []
        pred = dest
        while pred != None:
            path.append(pred)
            pred = predecessors.get(pred, None)
        print(*path[::-1])
    else:
        if not visited:
            distances[src] = 0
        for neighbor in graph[src]:
            if neighbor not in visited:
                new_distance = distances[src] + graph[src][neighbor]
                if new_distance < distances.get(neighbor, float('inf')):
                    distances[neighbor] = new_distance
                    predecessors[neighbor] = src
        visited.append(src)
        unvisited = {}
        for k in graph:
            if k not in visited:
                unvisited[k] = distances.get(k, float('inf'))
        x = min(unvisited, key=unvisited.get)
        dijkstra(graph, x, dest, visited, distances, predecessors)

n, m = map(int, input().split())
graph = dict()

for i in range(m):
    a, b, w = map(int, input().split())
    if a in graph:
        graph[a][b] = w
    else:
        graph[a] = {b: w}
    if b in graph:
        graph[b][a] = w
    else:
        graph[b] = {a: w}

try:
    dijkstra(graph, 1, n)
except:
    print(-1)


import heapq
import atexit
import io
import sys

_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def dijkstra(adj, source, target):
    INF = ((1 << 63) - 1) // 2
    pred = {x: x for x in adj}
    dist = {x: INF for x in adj}
    dist[source] = 0
    PQ = []
    heapq.heappush(PQ, [dist[source], source])

    while (PQ):
        u = heapq.heappop(PQ)
        u_dist = u[0]
        u_id = u[1]
        if u_dist == dist[u_id]:
            for v in adj[u_id]:
                v_id = v[0]
                w_uv = v[1]
                if dist[u_id] + w_uv < dist[v_id]:
                    dist[v_id] = dist[u_id] + w_uv
                    heapq.heappush(PQ, [dist[v_id], v_id])
                    pred[v_id] = u_id

    if target not in dist or dist[target] == INF:
        raise Exception("Invalid path")
    else:
        st = []
        node = target
        while True:
            st.append(str(node))
            if node == pred[node]:
                break
            node = pred[node]
        return st[::-1]

n, m = map(int, input().split())
graph = dict()

for i in range(m):
    a, b, w = map(int, input().split())
    if a in graph:
        graph[a].append((b, w))
    else:
        graph[a] = [(b, w)]
    if b in graph:
        graph[b].append((a, w))
    else:
        graph[b] = [(a, w)]

try:
    print(*map(int, dijkstra(graph, 1, n)))
except:
    print(-1)


import atexit
import io
import sys

_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def dijkstra(graph, src, dest, visited=[], distances={}, predecessors={}):
    if src not in graph:
        raise TypeError('The root of the shortest path tree cannot be found')
    if dest not in graph:
        raise TypeError('The shortest path cannot be found')
    if src == dest:
        path = []
        pred = dest
        while pred != None:
            path.append(pred)
            pred = predecessors.get(pred, None)
        print(*path[::-1])
    else:
        if not visited:
            distances[src] = 0
        for neighbor in graph[src]:
            if neighbor not in visited:
                new_distance = distances[src] + graph[src][neighbor]
                if new_distance < distances.get(neighbor, float('inf')):
                    distances[neighbor] = new_distance
                    predecessors[neighbor] = src
        visited.append(src)
        unvisited = {}
        for k in graph:
            if k not in visited:
                unvisited[k] = distances.get(k, float('inf'))
        x = min(unvisited, key=unvisited.get)
        dijkstra(graph, x, dest, visited, distances, predecessors)

n, m = map(int, input().split())
graph = dict()

for i in range(m):
    a, b, w = map(int, input().split())
    if a in graph:
        graph[a][b] = w
    else:
        graph[a] = {b: w}
    if b in graph:
        graph[b][a] = w
    else:
        graph[b] = {a: w}

try:
    dijkstra(graph, 1, n)
except:
    print(-1)


def dijkstra(graph, src, dest, visited=[], distances={}, predecessors={}):
    if src not in graph:
        raise TypeError('The root of the shortest path tree cannot be found')
    if dest not in graph:
        print(-1)
        exit(0)
    if src == dest:
        path = []
        pred = dest
        while pred != None:
            path.append(pred)
            pred = predecessors.get(pred, None)
        print(*path[::-1])
    else:
        if not visited:
            distances[src] = 0
        for neighbor in graph[src]:
            if neighbor not in visited:
                new_distance = distances[src] + graph[src][neighbor]
                if new_distance < distances.get(neighbor, float('inf')):
                    distances[neighbor] = new_distance
                    predecessors[neighbor] = src
        visited.append(src)
        unvisited = {}
        for k in graph:
            if k not in visited:
                unvisited[k] = distances.get(k, float('inf'))
        x = min(unvisited, key=unvisited.get)
        dijkstra(graph, x, dest, visited, distances, predecessors)

n, m = map(int, input().split())
graph = dict()

for i in range(m):
    a, b, w = map(int, input().split())
    if a in graph:
        graph[a][b] = w
    else:
        graph[a] = {b: w}
    if b in graph:
        graph[b][a] = w
    else:
        graph[b] = {a: w}

dijkstra(graph, 1, n)


# cf 20 C (2100)
import heapq
n, m = map(int, input().split()) # n=V, m=E
V = [ [] for _ in range(n + 1) ]

for _ in range(m):
    a, b, w = map(int, input().split())
    V[a].append((b, w))
    V[b].append((a, w))

visited = [False] * (n + 1)
prev = [None] * (n + 1)
node = 1
dist = [float("inf")] * (n + 1)
dist[node] = 0
Q = []

for node in range(n):
    heapq.heappush(Q, (dist[node], node))

while Q:
    _, node = heapq.heappop(Q)
    for dst_node, weight in V[node]:
        if dist[node] + weight < dist[dst_node]:
            dist[dst_node] = dist[node] + weight
            prev[dst_node] = node
    visited[node] = True
    Q = []
    for node in range(n):
        if not visited[node]:
            heapq.heappush(Q, (dist[node], node))
    if visited[n]:
        break

output = []
node = n
while node != 1:
    output.append(node)
    node = prev[node]
output.append(1)

print(" ".join(map(str, reversed(output))))


# cf 20 C (2100)
import heapq
n, m = map(int, input().split()) # n=V, m=E
V = [ [] for _ in range(n + 1) ]

for _ in range(m):
    a, b, w = map(int, input().split())
    V[a].append((b, w))
    V[b].append((a, w))

visited = [False] * (n + 1)
prev = [None] * (n + 1)
node = 1
dist = [float("inf")] * (n + 1)
dist[node] = 0
Q = []

for node in range(n + 1):
    heapq.heappush(Q, (dist[node], node))

while Q:
    _, node = heapq.heappop(Q)
    for dst_node, weight in V[node]:
        if dist[node] + weight < dist[dst_node]:
            dist[dst_node] = dist[node] + weight
            prev[dst_node] = node
    visited[node] = True
    Q = []
    for node in range(n + 1):
        if not visited[node]:
            heapq.heappush(Q, (dist[node], node))

if prev[n]:
    output = []
    node = n
    while node != 1:
        output.append(node)
        node = prev[node]
    output.append(1)
    print(" ".join(map(str, reversed(output))))
else:
    print(-1)


# cf 20 C (2100)
import heapq
n, m = map(int, input().split()) # n=V, m=E
V = [ [] for _ in range(n + 1) ]

for _ in range(m):
    a, b, w = map(int, input().split())
    V[a].append((b, w))
    V[b].append((a, w))

visited = [False] * (n + 1)
prev = [None] * (n + 1)
node = 1
dist = [float("inf")] * (n + 1)
dist[node] = 0
Q = []

for node in range(n + 1):
    heapq.heappush(Q, (dist[node], node))

while Q:
    _, node = heapq.heappop(Q)
    if visited[node]:
        continue
    for dst_node, weight in V[node]:
        if dist[node] + weight < dist[dst_node]:
            dist[dst_node] = dist[node] + weight
            prev[dst_node] = node
            heapq.heappush(Q, (dist[dst_node], dst_node))
    visited[node] = True

if prev[n]:
    output = []
    node = n
    while node != 1:
        output.append(node)
        node = prev[node]
    output.append(1)
    print(" ".join(map(str, reversed(output))))
else:
    print(-1)


# cf 20 C (2100)
import heapq
import sys

stdin = sys.stdin.read().split()
n, m, *edges = map(int, stdin)

#n, m = map(int, input().split()) # n=V, m=E
V = [ [] for _ in range(n + 1) ]

for i in range(m):
    a, b, w = edges[i * 3], edges[i * 3 + 1], edges[i * 3 + 2] # map(int, input().split())
    V[a].append((b, w))
    V[b].append((a, w))

visited = [False] * (n + 1)
prev = [None] * (n + 1)
node = 1
dist = [float("inf")] * (n + 1)
dist[node] = 0

Q = [ (dist[node], node) for node in range(n + 1) ]
heapq.heapify(Q)

while Q:
    _, node = heapq.heappop(Q)
    if visited[node]:
        continue
    for dst_node, weight in V[node]:
        if dist[node] + weight < dist[dst_node]:
            dist[dst_node] = dist[node] + weight
            prev[dst_node] = node
            heapq.heappush(Q, (dist[dst_node], dst_node))
    visited[node] = True

if prev[n]:
    output = []
    node = n
    while node != 1:
        output.append(node)
        node = prev[node]
    output.append(1)
    print(" ".join(map(str, reversed(output))))
else:
    print(-1)


from heapq import heappush, heappop
def dijkstra(graph):
    n = len(graph)
    INF = int(1e18)
    dist = [INF] * n
    pre = [-1] * n
    heap = [(0, 0)]
    dist[0] = 0
    while len(heap) > 0:
        d, u = heappop(heap)
        if d > dist[u]:
            continue
        for edge in graph[u]:
            v, w = edge[0], dist[u] + edge[1]
            if w < dist[v]:
                dist[v], pre[v] = w, u
                heappush(heap, (dist[v], v))
    if pre[n-1]==-1:
        return False
    i=n-1
    ans=[]
    while i!=-1:
        ans.append(i+1)
        i=pre[i]
    ans.reverse()
    print(*ans)
    return True

n,m=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
    a,b,w=map(int,input().split())
    g[a-1].append([b-1,w])
    g[b-1].append([a-1,w])
if not dijkstra(g):
    print(-1)


def relax(v):
    for i in range(len(g[v])):
        if g[v][i]!=0 and vis[i]==False and dis[v]+g[v][i]<dis[i]:
            f[i]=v
            dis[i]=dis[v]+g[v][i]

import math
n,m=map(int,input().split())
g=[[0]*(n+1) for _ in range(n+1)]
for _ in range(m):
    a,b,w=map(int,input().split())
    g[a][b]=w
    g[b][a]=w

dis=[math.inf]*(n+1)
dis[1]=0
vis=[False]*(n+1)
f=[-1]*(n+1)

ind=1
l=len(dis)
for _ in range(len(vis)):
    relax(ind)
    vis[ind]=True
    m=math.inf
    ind=-1
    for i in range(l):
        if vis[i]==False and dis[i]<m:
            m=dis[i]
            ind=i
    if ind==-1 or dis[ind]==math.inf:
        break
if dis[n]==math.inf:
    print(-1)
else:
    ans=[]
    i=n
    while i!=1:
        ans.append(i)
        i=f[i]
    ans.append(1)
    ans.reverse()
    print(*ans)


from sys import stdin
from heapq import heappush, heappop
def dijkstra(graph):
    n = len(graph)
    INF = int(1e18)
    dist = [INF] * n
    pre = [-1] * n
    heap = [(0, 0)]
    dist[0] = 0
    while len(heap) > 0:
        d, u = heappop(heap)
        if d > dist[u]:
            continue
        for edge in graph[u]:
            v, w = edge[0], dist[u] + edge[1]
            if w < dist[v]:
                dist[v], pre[v] = w, u
                heappush(heap, (dist[v], v))
    if pre[n-1]==-1:
        return False
    i=n-1
    ans=[]
    while i!=-1:
        ans.append(i+1)
        i=pre[i]
    ans.reverse()
    print(*ans)
    return True

n, m = [int(tmp) for tmp in stdin.readline().split()]
g=[[] for _ in range(n)]
for line in stdin.readlines():
    a,b,w=[int(tmp) for tmp in line.split()]
    g[a-1].append([b-1,w])
    g[b-1].append([a-1,w])
if not dijkstra(g):
    print(-1)


import heapq
from sys import stdin, stdout

# Dijktra's shortest path algorithm. Prints the path from source to target.
# If no path exists -1 is printed
# dictionary (hash map implementation) is used here instead of an array
# testing pypy 3.2.5

def dijkstra(adj, source, target):
    INF = ((1<<63) - 1)//2
    pred = { x:x for x in adj }
    dist = { x:INF for x in adj }
    dist[source] = 0
    Q = []
    heapq.heappush(Q, [dist[source], source])

    while(Q):
        u = heapq.heappop(Q)  # u is a tuple [u_dist, u_id]
        u_dist = u[0]
        u_id = u[1]
        if u_dist > dist[u_id]:
           continue
        if u_id == target:
            break
        for v in adj[u_id]:
           v_id = v[0]
           w_uv = v[1]
           if dist[u_id] +  w_uv < dist[v_id]:
               dist[v_id] = dist[u_id] + w_uv
               heapq.heappush(Q, [dist[v_id], v_id])
               pred[v_id] = u_id

    if dist[target]==INF:
        stdout.write("-1\n")
    else:
        st = []
        node = target
        while(True):
            st.append(str(node))
            if(node==pred[node]):
                break
            node = pred[node]
        path = st[::-1]
        stdout.write(" ".join(path) + "\n")

#----------------------------------------------------------

def main():
    n, m = [int(x) for x in stdin.readline().split()]
    adj = {}

    for i in range(m):
        a, b, w = stdin.readline().split()
        w = float(w)
        a = int(a)
        b = int(b)
        if not a in adj:
            adj[a] = [(b, w)]     # list of tuples
        else:
            adj[a].append((b, w))
        if not b in adj:
            adj[b] = [(a, w)]
        else:
            adj[b].append((a, w))

    source = 1
    target = n
    dijkstra(adj, source, target)

if __name__ == "__main__":
    main()


           if dist[u_id] +  w_uv < dist[v_id]:
               dist[v_id] = dist[u_id] + w_uv
               heapq.heappush(Q, [dist[v_id], v_id])
               pred[v_id] = u_id

    if dist[target]==INF:
        stdout.write("-1\n")
    else:
        st = []
        node = target
        while(True):
            st.append(str(node + 1))
            if(node==pred[node]):
                break
            node = pred[node]
        path = st[::-1]
        stdout.write(" ".join(path) + "\n")

#----------------------------------------------------------

def main():
    n, m = [int(x) for x in stdin.readline().split()]
    adj = [ [] for v in range(n) ]

    for i in range(m):
        a, b, w = stdin.readline().split()
        w = float(w)
        a = int(a)
        b = int(b)
        adj[a-1].append((b-1, w))
        adj[b-1].append((a-1, w))

    source = 0
    target = n - 1
    dijkstra(adj, source, target)

if __name__ == "__main__":
    main()


import heapq
from sys import stdin, stdout

# Dijktra's shortest path algorithm. Prints the path from source to target.
# If no path exists -1 is printed
# testing: in this version I have replaced the dictionaries by lists
# testing pypy 3.2.5

def dijkstra(adj, source, target):
    n = len(adj)
    INF = ((1<<63) - 1)//2
    pred = [ x for x in range(n) ]
    dist = [ INF for x in range(n) ]
    visited = set()
    dist[source] = 0
    Q = []
    heapq.heappush(Q, [dist[source], source])

    while(Q):
        u = heapq.heappop(Q)  # u is a tuple [u_dist, u_id]
        u_dist = u[0]
        u_id = u[1]
        visited.add(u_id)
        if u_dist > dist[u_id]:
           continue
        if u_id == target:
            break
        for v in adj[u_id]:
           v_id = v[0]
           w_uv = v[1]
           if dist[u_id] +  w_uv < dist[v_id]:
               dist[v_id] = dist[u_id] + w_uv
               heapq.heappush(Q, [dist[v_id], v_id])
               pred[v_id] = u_id

    if dist[target]==INF:
        stdout.write("-1\n")
    else:
        st = []
        node = target
        while(True):
            st.append(str(node + 1))
            if(node==pred[node]):
                break
            node = pred[node]
        path = st[::-1]
        stdout.write(" ".join(path) + "\n")

#----------------------------------------------------------

def main():
    n, m = [int(x) for x in stdin.readline().split()]
    adj = [ [] for v in range(n) ]

    for i in range(m):
        a, b, w = stdin.readline().split()
        w = float(w)
        a = int(a)
        b = int(b)
        adj[a-1].append((b-1, w))
        adj[b-1].append((a-1, w))

    source = 0
    target = n - 1
    dijkstra(adj, source, target)

if __name__ == "__main__":
    main()


import heapq
from sys import stdin, stdout

# Dijktra's shortest path algorithm. Prints the path from source to target.
# If no path exists -1 is printed
# dictionary (hash map implementation) is used here instead of an array
# testing pypy 3.2.5

def dijkstra(adj, source, target):
    INF = ((1<<63) - 1)//2
    pred = { x:x for x in adj }
    dist = { x:INF for x in adj }
    visited = set()
    dist[source] = 0
    Q = []
    heapq.heappush(Q, [dist[source], source])

    while(Q):
        u = heapq.heappop(Q)  # u is a tuple [u_dist, u_id]
        u_dist = u[0]
        u_id = u[1]
        visited.add(u_id)
        if u_dist > dist[u_id]:
           continue
        if u_id == target:
            break
        for v in adj[u_id]:
           v_id = v[0]
           w_uv = v[1]
           if dist[u_id] +  w_uv < dist[v_id]:
               dist[v_id] = dist[u_id] + w_uv
               heapq.heappush(Q, [dist[v_id], v_id])
               pred[v_id] = u_id

    if dist[target]==INF:
        stdout.write("-1\n")
    else:
        st = []
        node = target
        while(True):
            st.append(str(node))
            if(node==pred[node]):
                break
            node = pred[node]
        path = st[::-1]
        stdout.write(" ".join(path) + "\n")

#----------------------------------------------------------

def main():
    n, m = [int(x) for x in stdin.readline().split()]
    adj = { v : [] for v in range(1,n+1)}

    for i in range(m):
        a, b, w = stdin.readline().split()
        w = float(w)
        a = int(a)
        b = int(b)
        adj[a].append((b, w))
        adj[b].append((a, w))

    source = 1
    target = n
    dijkstra(adj, source, target)

if __name__ == "__main__":
    main()


import heapq
from sys import stdin, stdout

# Dijktra's shortest path algorithm. Prints the path from source to target.
# If no path exists -1 is printed
# Testing bidirectional Dijkstra algorithm

# Testing if I can improve my last submission (bidirectional Dijkstra)
# with submission no. 10418470
# by replacing the dictionaries by lists

# I'm also using stdin and stdout instead of input() and print()
# -> Result: 608ms, my fastest time so far

# Testing, if Pypy3 improves my submission 10654370

def dijkstra(adj, source, target):
    n = len(adj)
    INF = ((1<<63) - 1)//2
    pred = [ x for x in range(n) ]
    dist = [ INF for x in range(n) ]
    pred_b = [ x for x in range(n) ]
    dist_b = [ INF for x in range(n) ]
    dist[source] = 0
    dist_b[target] = 0
    Q = []
    Q_b = []
    S = set()
    S_b = set()

    heapq.heappush(Q, [dist[source], source])
    heapq.heappush(Q_b, [dist_b[target], target])

    found_common_node = False

    while(Q and Q_b):

        u = heapq.heappop(Q_b)  # u is a tuple [u_dist, u_id]
        u_dist = u[0]
        u_id = u[1]
        S_b.add(u_id)

        if u_dist == dist_b[u_id]:
            if u_id in S:  # stop criterion
                found_common_node = True
                break
            for v in adj[u_id]:
                v_id = v[0]
                w_uv = v[1]
                if dist_b[u_id] +  w_uv < dist_b[v_id]:
                    dist_b[v_id] = dist_b[u_id] + w_uv
                    heapq.heappush(Q_b, [dist_b[v_id], v_id])
                    pred_b[v_id] = u_id

        u = heapq.heappop(Q)  # u is a tuple [u_dist, u_id]
        u_dist = u[0]
        u_id = u[1]
        S.add(u_id)

        if u_dist == dist[u_id]:
            if u_id == target:
                break
            if u_id in S_b:  # stop criterion
                found_common_node = True
                break
            for v in adj[u_id]:
                v_id = v[0]
                w_uv = v[1]
                if dist[u_id] +  w_uv < dist[v_id]:
                    dist[v_id] = dist[u_id] + w_uv
                    heapq.heappush(Q, [dist[v_id], v_id])
                    pred[v_id] = u_id

    #print(Q)
    #print(Q_b)

    # right Dijkstra has finished before left Dijkstra
    if not Q_b and not found_common_node:
        # print("option 2")
        if dist_b[source] == INF:
            print("-1")
            return
        else:
            st = []
            node = source
            while(True):
                st.append(str(node + 1))
                if(node==pred_b[node]):
                    break
                node = pred_b[node]
            #path = st[::-1]
            path = st
            stdout.write(" ".join(path) + "\n")
            return

    # left Dijkstra has finished before right Dijkstra
    if not Q and not found_common_node:
        # print("option 1")
        if dist[target] == INF:
            stdout.write("-1\n")
            return
        else:
            st = []
            node = target
            while(True):
                st.append(str(node + 1))
                if(node==pred[node]):
                    break
                node = pred[node]
            path = st[::-1]
            stdout.write(" ".join(path) + "\n")
            return

    # no common node found
    # -> there is no shortest path between source and target
    if not found_common_node:
        stdout.write("-1\n")

    # found a common node
    else:
        nodes_in_Q = set()
        while(Q):
            u = heapq.heappop(Q)
            u_id = u[1]
            nodes_in_Q.add(u_id)

        nodes_in_Q_b = set()
        while(Q_b):
            u = heapq.heappop(Q_b)
            u_id = u[1]
            nodes_in_Q_b.add(u_id)

        candidates = (S | nodes_in_Q) & (S_b | nodes_in_Q_b)
        min_dist = INF
        min_node = "none"
        for node in candidates:
            middle_dist = dist[node] + dist_b[node]
            if middle_dist < min_dist:
                min_dist = middle_dist
                min_node = node

        st = []
        node = min_node
        while(True):
            st.append(str(node + 1))
            if(node==pred[node]):
                break
            node = pred[node]
        path_forward = st[::-1]

        st = []
        node = min_node
        while(True):
            st.append(str(node + 1))
            if(node==pred_b[node]):
                break
            node = pred_b[node]

        path = " ".join(path_forward) + " " +  " ".join(st[1:])
        stdout.write(path + "\n")

#----------------------------------------------------------

def main():
    n, m = [int(c) for c in input().split()]
    adj = [ [] for _ in range(n) ]

    for _ in range(m):
        a, b, w = [int(c) for c in stdin.readline().split()]
        adj[a-1].append((b-1, w))
        adj[b-1].append((a-1, w))

    source = 0
    target = n-1
    dijkstra(adj, source, target)

#----------------------------------------------------------

if __name__ == "__main__":
    main()


from heapq import heappop, heappush
inf = 10 ** 16 + 7
n, m = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(m):
    u, v, w = map(int, input().split())
    adj[u - 1].append((w, v - 1))
    adj[v - 1].append((w, u - 1))
d = [inf] * n
trace = [-1] * n
d[0] = 0
q = [(d[0], 0)]
while q:
    du, u = heappop(q)
    if du == d[u]:
        for w, v in adj[u]:
            if d[v] > d[u] + w:
                d[v], trace[v] = d[u] + w, u
                heappush(q, (d[v], v))
u = n - 1
if d[u] == inf:
    print(-1)
else:
    st = []
    while u != -1:
        st.append(u)
        u = trace[u]
    st = reversed(st)
    print(*(x + 1 for x in st))


import sys
from heapq import heappush, heappop
input = sys.stdin.readline
n, m = map(int, input().split())
adj = [[] for _ in range(n)]
for _ in range(m):
    u, v, w = map(int, input().split())
    adj[u - 1].append((v - 1, w))
    adj[v - 1].append((u - 1, w))
inf = 10**16 + 7
d = [inf] * n
trace = [-1] * n
d[0] = 0
q = [(d[0], 0)]
while q:
    du, u = heappop(q)
    if du == d[u]:
        for v, w in adj[u]:
            if d[v] > du + w:
                d[v], trace[v] = du + w, u
                heappush(q, (d[v], v))
u = n - 1
if d[u] == inf:
    print(-1)
else:
    st = []
    while u != -1:
        st.append(u + 1)
        u = trace[u]
    print(*reversed(st))


import queue as Q
inf = 10 ** 16 + 7
n, m = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(m):
    u, v, w = map(int, input().split())
    adj[u - 1].append((w, v - 1))
    adj[v - 1].append((w, u - 1))
q = Q.PriorityQueue()
d = [inf] * n
trace = [-1] * n
d[0] = 0
q.put((d[0],0))
while not q.empty():
    top = q.get()
    du, u = top
    if du != d[u]:
        continue
    for e in adj[u]:
        w, v = e
        if d[v] > d[u] + w:
            d[v] = d[u] + w
            trace[v] = u;
            q.put((d[v],v))
u = n - 1
st = []
while u != -1:
    st.append(u)
    u = trace[u]
print(*(x + 1 for x in reversed(st)))


import queue as Q
inf = 10 ** 16 + 7
n, m = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(m):
    u, v, w = map(int, input().split())
    adj[u - 1].append((w, v - 1))
    adj[v - 1].append((w, u - 1))
q = Q.PriorityQueue()
d = [inf] * n
trace = [-1] * n
d[0] = 0
q.put((d[0],0))
while not q.empty():
    top = q.get()
    du, u = top
    if du != d[u]:
        continue
    for e in adj[u]:
        w, v = e
        if d[v] > d[u] + w:
            d[v] = d[u] + w
            trace[v] = u;
            q.put((d[v],v))
u = n - 1
if d[u] == inf:
    print(-1)
else:
    st = []
    while u != -1:
        st.append(u)
        u = trace[u]
    st = reversed(st)
    print(*(x + 1 for x in st))


import sys
from heapq import heappop, heappush
input = sys.stdin.readline
inf = 10 ** 16 + 7
n, m = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(m):
    u, v, w = map(int, input().split())
    adj[u - 1].append((w, v - 1))
    adj[v - 1].append((w, u - 1))
d = [inf] * n
trace = [-1] * n
d[0] = 0
q = [(d[0], 0)]
while q:
    du, u = heappop(q)
    if du == d[u]:
        for w, v in adj[u]:
            if d[v] > d[u] + w:
                d[v], trace[v] = d[u] + w, u
                heappush(q, (d[v], v))
u = n - 1
if d[u] == inf:
    print(-1)
else:
    st = []
    while u != -1:
        st.append(u + 1)
        u = trace[u]
    print(*reversed(st))


import sys
import queue as Q
input = sys.stdin.readline
inf = 10 ** 16 + 7
n, m = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(m):
    u, v, w = map(int, input().split())
    adj[u - 1].append((w, v - 1))
    adj[v - 1].append((w, u - 1))
q = Q.PriorityQueue()
d = [inf] * n
trace = [-1] * n
d[0] = 0
q.put((d[0],0))
while not q.empty():
    top = q.get()
    du, u = top
    if du != d[u]:
        continue
    for e in adj[u]:
        w, v = e
        if d[v] > d[u] + w:
            d[v] = d[u] + w
            trace[v] = u;
            q.put((d[v],v))
u = n - 1
if d[u] == inf:
    print(-1)
else:
    st = []
    while u != -1:
        st.append(u + 1)
        u = trace[u]
    print(*reversed(st))


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(str(v + 1))
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append("1")

    print(" ".join(reversed(path))

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys
import heapq

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    q = PriorityQueue()
    heapq.heappush(q, (0, 0))

    while (len(q) > 0):
        val = heapq.heappop(q)
        cost = val[1]
        node = val[0]

        if (cost != d[v]):
            continue

        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v
                heapq.heappush(q, (d[to], to))

    # for i in range(n):
    #     v = -1
    #     for j in range(n):
    #         if ((not u[j]) and (v == -1 or d[j] < d[v])):
    #             v = j

    #     if (d[v] == sys.maxsize):
    #         break

    #     u[v] = True
    #     for edge in adj[v]:
    #         to = edge[0]
    #         cost = edge[1]

    #         if (d[v] + cost < d[to]):
    #             d[to] = d[v] + cost
    #             p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(str(v + 1))
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append("1")

    print(" ".join(reversed(path)))

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    int n = len(adj)
    d = [sys.maxsize for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for (i in range(n)):
        int v = -1
        for (j in range(n)):
            if (not u[j] and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for (edge in adj[v]):
            to = edge[0]
            len = edge[1]

            if (d[v] + len < d[to]):
                d[to] = d[v] + len
                p[to] = v

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)
    path.reverse()

    for i in range(len(path)):
        print(path[i])

num_vertices, predecessors = djikstra()
backtrack(num_vertices, predecessors)


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [n + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == n+1):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)
    path.reverse()

    for i in range(len(path)):
        print(path[i])

num_vertices, predecessors = djikstra()
# backtrack(num_vertices, predecessors)


import sys
import heapq

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [1000000000 for i in range(num_vertices)]
    p = [-1 for i in range(num_vertices)]

    d[0] = 0
    q = []
    heapq.heappush(q, (0, 0))

    while (len(q) > 0):
        val = heapq.heappop(q)
        cost = val[0]
        v = val[1]

        if (cost != d[v]):
            continue

        for edge in adj[v]:
            to = edge[0]
            edge_len = edge[1]

            if (d[v] + edge_len < d[to]):
                d[to] = d[v] + edge_len
                p[to] = v
                heapq.heappush(q, (d[to], to))

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(str(v + 1))
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append("1")

    print(" ".join(reversed(path)))

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if (not u[j] and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            len = edge[1]

            if (d[v] + len < d[to]):
                d[to] = d[v] + len
                p[to] = v

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)
    path.reverse()

    for i in range(len(path)):
        print(path[i])

num_vertices, predecessors = djikstra()
backtrack(num_vertices, predecessors)


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [n + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == n+1):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            len = edge[1]

            if (d[v] + len < d[to]):
                d[to] = d[v] + len
                p[to] = v

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)
    path.reverse()

    for i in range(len(path)):
        print(path[i])

num_vertices, predecessors = djikstra()
backtrack(num_vertices, predecessors)


import sys
import heapq

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [100000000000 for i in range(num_vertices)]
    p = [-1 for i in range(num_vertices)]

    d[0] = 0
    q = []
    heapq.heappush(q, (0, 0))

    while (len(q) > 0):
        val = heapq.heappop(q)
        cost = val[0]
        v = val[1]

        if (cost != d[v]):
            continue

        for edge in adj[v]:
            to = edge[0]
            edge_len = edge[1]

            if (d[v] + edge_len < d[to]):
                d[to] = d[v] + edge_len
                p[to] = v
                heapq.heappush(q, (d[to], to))

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(str(v + 1))
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append("1")

    print(" ".join(reversed(path)))

djikstra()


import sys
import heapq

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    q = []
    heapq.heappush(q, (0, 0))

    while (len(q) > 0):
        val = heapq.heappop(q)
        cost = val[1]
        node = val[0]

        if (cost != d[v]):
            continue

        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v
                heapq.heappush(q, (d[to], to))

    # for i in range(n):
    #     v = -1
    #     for j in range(n):
    #         if ((not u[j]) and (v == -1 or d[j] < d[v])):
    #             v = j

    #     if (d[v] == sys.maxsize):
    #         break

    #     u[v] = True
    #     for edge in adj[v]:
    #         to = edge[0]
    #         cost = edge[1]

    #         if (d[v] + cost < d[to]):
    #             d[to] = d[v] + cost
    #             p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(str(v + 1))
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append("1")

    print(" ".join(reversed(path)))

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    if (num_vertices > num_edges + 1):
        print("-1")
        return

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        print(v + 1)
        path.append(v + 1)
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append(1)

    for i in reversed(path):
        print(i)

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append(1)

    print(" ".join(map(str,reversed(path))))

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys
import heapq

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize for i in range(num_vertices)]
    p = [-1 for i in range(num_vertices)]

    d[0] = 0
    q = []
    heapq.heappush(q, (0, 0))

    while (len(q) > 0):
        val = heapq.heappop(q)
        cost = val[0]
        v = val[1]

        if (cost != d[v]):
            continue

        for edge in adj[v]:
            to = edge[0]
            edge_len = edge[1]

            if (d[v] + edge_len <= d[to]):
                d[to] = d[v] + edge_len
                p[to] = v
                heapq.heappush(q, (d[to], to))

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(str(v + 1))
        old_v = v
        v = p[v]
        if (v == -1):
            print(old_v)
            print("-1")
            return

    path.append("1")

    print(" ".join(reversed(path)))

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        int v = -1
        for j in range(n):
            if (not u[j] and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for (edge in adj[v]):
            to = edge[0]
            len = edge[1]

            if (d[v] + len < d[to]):
                d[to] = d[v] + len
                p[to] = v

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)
    path.reverse()

    for i in range(len(path)):
        print(path[i])

num_vertices, predecessors = djikstra()
backtrack(num_vertices, predecessors)


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [n + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == n+1):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)
    path.reverse()

    for i in range(len(path)):
        print(path[i])

num_vertices, predecessors = djikstra()
backtrack(num_vertices, predecessors)


import sys
import heapq

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    q = []
    heapq.heappush(q, (0, 0))

    while (len(q) > 0):
        print('yessir')
        val = heapq.heappop(q)
        cost = val[0]
        node = val[1]

        if (cost != d[v]):
            continue

        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v
                heapq.heappush(q, (d[to], to))

    # for i in range(n):
    #     v = -1
    #     for j in range(n):
    #         if ((not u[j]) and (v == -1 or d[j] < d[v])):
    #             v = j

    #     if (d[v] == sys.maxsize):
    #         break

    #     u[v] = True
    #     for edge in adj[v]:
    #         to = edge[0]
    #         cost = edge[1]

    #         if (d[v] + cost < d[to]):
    #             d[to] = d[v] + cost
    #             p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(str(v + 1))
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append("1")

    print(" ".join(reversed(path)))

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    if (num_vertices > num_edges + 1):
        print("-1")
        return

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [n + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == n+1):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append(1)

    for i in reversed(path):
        print(i)

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [n + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == n+1):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

num_vertices, predecessors = djikstra()
backtrack(num_vertices, predecessors)


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(str(v + 1))
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append("1")

    print(" ".join(reversed(path)))

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for (i in range(n)):
        int v = -1
        for (j in range(n)):
            if (not u[j] and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for (edge in adj[v]):
            to = edge[0]
            len = edge[1]

            if (d[v] + len < d[to]):
                d[to] = d[v] + len
                p[to] = v

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)
    path.reverse()

    for i in range(len(path)):
        print(path[i])

num_vertices, predecessors = djikstra()
backtrack(num_vertices, predecessors)


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    # if (num_vertices > num_edges + 1):
    #     print("-1")
    #     return

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append(1)

    for i in reversed(path):
        print(i)

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    if (num_vertices > num_edges + 1):
        print("-1")
        return

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [n + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == n+1):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = p[v]

    path.append(1)

    for i in reversed(path):
        print(i)

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

num_vertices, predecessors = djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [n + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == n+1):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    print("1 0")

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

num_vertices, predecessors = djikstra()
# backtrack(num_vertices, predecessors)


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    if (num_vertices > num_edges + 1):
        print("-1")
        return

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [n + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == n+1):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

num_vertices, predecessors = djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append(1)

    print(" ".join(map(str,reversed(path)))

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys
import heapq

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [sys.maxsize for i in range(num_vertices)]
    p = [-1 for i in range(num_vertices)]

    d[0] = 0
    q = []
    heapq.heappush(q, (0, 0))

    while (len(q) > 0):
        val = heapq.heappop(q)
        cost = val[0]
        v = val[1]

        if (cost != d[v]):
            continue

        for edge in adj[v]:
            to = edge[0]
            edge_len = edge[1]

            if (d[v] + edge_len < d[to]):
                d[to] = d[v] + edge_len
                p[to] = v
                heapq.heappush(q, (d[to], to))

    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(str(v + 1))
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append("1")

    print(" ".join(reversed(path)))

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]
    num_edges = input_1[1]

    if (num_vertices > num_edges + 1):
        print("-1")
        return

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    n = len(adj)
    d = [n + 1 for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for i in range(n):
        v = -1
        for j in range(n):
            if ((not u[j]) and (v == -1 or d[j] < d[v])):
                v = j

        if (d[v] == n+1):
            break

        u[v] = True
        for edge in adj[v]:
            to = edge[0]
            cost = edge[1]

            if (d[v] + cost < d[to]):
                d[to] = d[v] + cost
                p[to] = v

    v = num_vertices - 1
    path = []
    while (v != 0):
        print(v + 1)
        path.append(v + 1)
        v = p[v]
        if (v == -1):
            print("-1")
            return

    path.append(1)

    for i in reversed(path):
        print(i)

def backtrack(num_vertices, predecessors):
    v = num_vertices - 1
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)

    for i in reversed(path):
        print(i)

djikstra()


import sys

def djikstra():
    data = [line.rstrip().split() for line in sys.stdin.readlines()]
    data = [[int(x) for x in row] for row in data]

    input_1 = data[0]
    num_vertices = input_1[0]

    adj = [[] for i in range(num_vertices)]

    for i in range(1, len(data)):
        v1 = data[i][0] - 1
        v2 = data[i][1] - 1
        cost = data[i][2]

        adj[v1].append((v2, cost))
        adj[v2].append((v1, cost))

    int n = len(adj)
    d = [sys.maxsize for i in range(n)]
    p = [-1 for i in range(n)]
    u = [False for i in range(n)]

    d[0] = 0
    for (i in range(n)):
        int v = -1
        for (j in range(n)):
            if (!u[j] and (v == -1 or d[j] < d[v]):
                v = j

        if (d[v] == sys.maxsize):
            break

        u[v] = True
        for (edge in adj[v]):
            to = edge[0]
            len = edge[1]

            if (d[v] + len < d[to]):
                d[to] = d[v] + len
                p[to] = v

    return num_vertices, p

def backtrack(num_vertices, predecessors):
    v = num_vertices
    path = []
    while (v != 0):
        path.append(v + 1)
        v = predecessors[v]

    path.append(1)
    path.reverse()

    for i in range(len(path)):
        print(path[i])

num_vertices, predecessors = djikstra()
backtrack(num_vertices, predecessors)


#include <stdio.h>
#include <math.h>

int main()
{
    long double s;
    long int x,l,h;
    scanf("%ld %ld", &h,&l);
    x=(pow(l,2)-pow(h,2));
    s=x/(2.0*h);
    printf("%.100lf\n", s);
}


#include <stdio.h>
#include <math.h>

int main()
{
    double s;
    long int x,l,h;
    scanf("%ld %ld", &h,&l);
    x=(pow(l,2)-pow(h,2));
    s=x/(2.0*h);
    printf("%.13lf\n", s);
}


#include <stdio.h>

double h,l,x;

int main()
{
	scanf("%lf %lf", &h, &l);
	x = (l*l - h*h) / (2 * h);
	printf("%lf", x);
}


#include <stdio.h>

float h,l,x;

int main()
{
	scanf("%f %f", &h, &l);
	x = (l*l - h*h) / (2 * h);
	printf("%f", x);
}


#include<stdio.h>
int main()
{
    double h,l;
    scanf("%lf %lf",&h,&l);
    double x=(((l*l)-(h*h))/(2*h));
    printf("%.13lf\n",x);
    return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
    double x,l,h;
    scanf("%lf%lf",&h,&l);
    x=(l*l-h*h)/2*h;
    printf("%lf\n",x);
}


#include<stdio.h>
int main()
{
    double a,b,ans;
    scanf("%lf%lf",&a,&b);
    ans=b*b-a*a;
    ans/=2*a;
    printf("%.12f\n",ans);
    return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
    double x,l,h;
    scanf("%lf%lf",&h,&l);
    x=(l*l-h*h)/2*h;
    printf("%.13lf\n",x);
}


#include<stdio.h>
#include<math.h>
int main()
{
    double l,h;
    scanf("%lf %lf",&h,&l);
    double x=(((l*l)-(h*h))/(2*h));
    printf("%.13lf\n",x);
}


#include<stdio.h>
#include<math.h>
int main()
{
    double x,l,h;
    scanf("%lf%lf",&h,&l);
    x=((l*l)-(h*h))/(2*h);
    printf("%.13lf\n",x);
}


#include<stdio.h>
int main()
{
	double a,b;
	scanf("%lf%lf",&a,&b);
	double s=((b*b)-(a*a))/2*a;
	printf("%.13lf\n",s);
	return 0;
}


#include<stdio.h>

int main(){

    double l,h;
    scanf("%lf %lf", &h, &l);

    double res = 1.0*(l*l - h*h) / (2.0*h);

    printf("%.10f\n",res);
}


#include <stdio.h>
main();

    int main() {
     double h, l;
    scanf("%lf%lf", &h, &l);
    printf("%.13f\n", (l*l-h*h)/(2.0*h));
}


int main(){

    int l,h;
    scanf("%d %d", &h, &l);

    double res = (l*l - h*h) / (2.0*h);

    printf("%.13f\n",res);
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int l,h;

    cin>>h>>l;

    double res = (l*l - h*h) / (2.0*h);

    printf("%.13f\n",res);
}


#include<stdio.h>

int main(){

    int l,h;
    scanf("%d %d", &h, &l);

    double res = (l*l - h*h) / (2.0*h);

    printf("%.13f\n",res);
}


#include<stdio.h>

int main(){

    int l,h;
    scanf("%d %d", &h, &l);

    double res = 1.0*(l*l - h*h) / (2.0*h);

    printf("%.10f\n",res);
}


#include<bits/stdc++.h>
using namespace std;

int main(){

    double l,h;
    scanf("%lf %lf", &h, &l);

    double res = 1.0*(l*l - h*h) / (2.0*h);

    printf("%.10lf\n",res);
}


#include <stdio.h>
int main(){

    int main() {
     int h, l;
    scanf("%lf%lf", &h, &l);
    printf("%.10lf\n", (l*l-h*h)/(2.0*h));
}


#include <stdio.h>
main();

    int main() {
     double h, l;
    scanf("%lf%lf", &h, &l);
    printf("%.13lf\n", 1.0*(l*l-h*h)/(2.0*h));
}


#include <stdio.h>
main();

    int main() {
     double h, l;
    scanf("%lf%lf", &h, &l);
    printf("%.13lf\n", (l*l-h*h)/(2.0*h));
}


#include<stdio.h>
int main(void)
{
	int a,b;
	double c;
	scanf("%d %d",&a,&b);
	c=(double)(b*b-a*a)/(2*a);

	printf("%f",c);

	return 0;

 }


#include<stdio.h>
#include<math.h>
int main(void)
{
	long double a,b,c;
	scanf("%llf %llf",&a,&b);
	c=(b*b-a*a)/(2*a);

	printf("%llf",c);

	return 0;

 }


#include<stdio.h>
#include<math.h>
int main(void)
{
	float a,b,c;
	scanf("%f %f",&a,&b);
	c=(b*b-a*a)/(2*a);

	printf("%f",c);

	return 0;

 }


#include<stdio.h>
#include<math.h>
int main(void)
{
	double a,b,c;
	scanf("%lf %lf",&a,&b);
	c=(b*b-a*a)/(2*a);

	printf("%lf",c);

	return 0;

 }


#include<stdio.h>
#include<math.h>
int main(void)
{
	 double a,b,c;
	scanf("%lf %lf",&a,&b);
	c=(b*b-a*a)/(2*a);

	printf("%lf",c);

	return 0;

 }


#include<stdio.h>
int main(void)
{
	int a,b;
	double c;
	scanf("%d %d",&a,&b);
	c=(b*b-a*a)/(2*a);

	printf("%f",c);

	return 0;

 }


#include<stdio.h>
#include<math.h>
int main(){
    int h,l;
     long double a;
    scanf("%d %d",&h,&l);
    a=(double)(l*l-h*h)/(2*h);
    printf("%0.13Lf",a);
    return 0;

}


#include<stdio.h>
#include<math.h>
int main(){
    long long h,l;
    long double a;
    scanf("%I64d %I64d",&h,&l);
    a=( long double)(l*l-h*h)/(2*h);
    printf("%0.13Lf",a);
    return 0;

}


#include<stdio.h>
#include<math.h>
int main(){
    int h,l;
     long double a;
    scanf("%d %d",&h,&l);
    a=(long double)(l*l-h*h)/(2*h);
    printf("%0.13Lf",a);
    return 0;

}


#include<stdio.h>
int main()
{
int H,L;
float A;
scanf("%d %d",&H,&L);
A=(L*L-H*H)/(1.0*2*H);
printf("%0.8f\n",A);
return 0;
}


#include<stdio.h>
int main()
{
long long H,L;
float A;
scanf("%lld %lld",&H,&L);
A=(L*L-H*H)/(1.0*2*H);
printf("%0.8f\n",A);
return 0;
}


#include <stdio.h>
#include<math.h>
int main()
{
       float d,h,l;
        scanf("%f%f",&h,&l);
        d=(l*l-h*h)/(2*h);
        printf("%.13f\n",d);
}


#include <stdio.h>
#include<math.h>
int main()
{
       float d,h,l;
        scanf("%f%f",&h,&l);
        d=(l*l-h*h)/(2*h);
        printf("%.13lf\n",d);
}


#include <stdio.h>
#include<math.h>

int main()
{
       float d,h,l;
        scanf("%f%f",&h,&l);
        d=(l*l-h*h)/(2*h);
        printf("%.13lf\n",d);
}


#include <stdio.h>
int main() {
  long long int h,l,m;
  double n;
  scanf("%I64d %I64d",&h,&l);
  m=l*l-h*h;
  n=(double)m;
  n/=2;
  n/=h;
  printf("%lf",n);
}


#include <stdio.h>
int main() {
  long long int h,l,m;
  double n;
  scanf("%I64d %I64d",&h,&l);
  m=l*l-h*h;
  n=(double)m;
  n/=2;
  n/=h;
  printf("%f",n);
}


#include <stdio.h>
int main() {
  long long int h,l,m;
  scanf("%I64d %I64d",&h,&l);
  m=l*l-h*h;
  printf("%0.13lf",(double)m/(2*h));
}


#include <stdio.h>
int main() {
  long long int h,l,m;
  scanf("%I64d %I64d",&h,&l);
  m=l*l-h*h;
  printf("%llf",(double)m/(2*h));
}


#include <stdio.h>
int main() {
  long long int h,l,m;
  double n;
  scanf("%I64d %I64d",&h,&l);
  m=l*l-h*h;
  n=(double)m;
  n/=2;
  n/=h;
  printf("%0.13lf",n);
}


#include <stdio.h>
int main() {
  int h,l;
  scanf("%d %d",&h,&l);
  printf("%lf",(double)(l*l-h*h)/(2*h));
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (void){
	double h, l;
	double ans;
	while(scanf("%lf", &h) == 1){
		scanf("%lf", &l);
		ans =(l*l)/(2.*h) - (h/2.);
		printf("%.12f\n", ans);
	}
	return 0;

}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (void){
	int h, l;
	double ans;
	while(scanf("%d", &h) == 1){
		scanf("%d", &l);
		ans = (l*l - h*h)/2.;
		ans = ans/(double)h;
		printf("%.12f\n", ans);
	}
	return 0;

}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main (void){
	int h, l;
	while(scanf("%d", &h) == 1){
		scanf("%d", &l);
		double ans;
		ans = (l*l - h*h)/2.;
		ans = ans/h;
		printf("%.12lf\n", ans);
	}
	return 0;

}


#include <stdio.h>

int main()
{
    double h, l;
    scanf("%lf %lf", &h, &l);
    double x = (l * l + h * h) / (2 * h);
    printf("%lf\n", x - h);
    return 0;
}


#include <stdio.h>

int main()
{
    float h, l;
    scanf("%f %f", &h, &l);
    float x = (l * l + h * h) / (2 * h) - h;
    printf("%f\n", x);
    return 0;
}


#include <stdio.h>

int main()
{
    double h, l;
    scanf("%lf %lf", &h, &l);
    double x = (l * l + h * h) / (2 * h)-h;
    printf("%lf\n", x);
    return 0;
}


#include <stdio.h>

int main()
{
    int h, l;
    scanf("%d %d", &h, &l);
    double x = ((double)l * l + (double)h * h) / (2 * h);
    printf("%lf\n", x - h);
    return 0;
}


#include <stdio.h>

int main()
{
    float h,l,res;
    scanf("%f %f", &h, &l);
    res = ((l*l)-(h*h))/(2*h);

    printf("%.13f\n",res);

    return 0;
}


#include <stdio.h>

int main()
{
    double h,l,res;
    scanf("%lf %lf", &h, &l);
    res = ((l*l)-(h*h))/(2*h);

    printf("%.13lf\n",res);

    return 0;
}


#include<stdio.h>
int main(){
    int H,L;
    double depth;
    scanf("%d%d",&H,&L);
    depth=(H*H+L*L)*1.0/(2.0*H);
    printf("%lf\n",depth-1.0*H);
}


#include<stdio.h>
int main(){
    int H,L;
    double depth;
    scanf("%d%d",&H,&L);
    depth=(H*H+L*L)*1.0/(2.0*H);
    printf("%f\n",depth-1.0*H);
}


#include<stdio.h>
int main(){
    int H,L;
    double depth;
    scanf("%d%d",&H,&L);
    double h=H*(double)1.0;
    double l=L*(double)1.0;
    depth=(l*l-h*h)/((double)2*h);
    printf("%f\n",depth);
}


#include<stdio.h>
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r", stdin);
		freopen("output.txt","w", stdout);
	#endif
	int h,l;double s;
	scanf("%d%d",&h,&l);
	s=((l*l)-(h*h))/(2.0*h);
	printf("%lf",s);
	return 0;
}


#include<stdio.h>
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r", stdin);
		freopen("output.txt","w", stdout);
	#endif
	int h,l;double s;
	scanf("%d%d",&h,&l);
	s=((l*l)-(h*h))/(2.0*h);
	printf("%f",s);
	return 0;
}


#include<stdio.h>
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r", stdin);
		freopen("output.txt","w", stdout);
	#endif
	int long long h,l;double s;
	scanf("%lld%lld",&h,&l);
	s=((l*l)-(h*h))/(2.0*h);
	printf("%f",s);
	return 0;
}


#include<stdio.h>
int main()
{
    double h,l,d;
    scanf("%lf %lf",&h,&l);
    d=(((l*l)-(h*h))/(2*h));
    printf("%0.9lf",d);
}


#include<stdio.h>
int main()
{
    double h,l,d;
    scanf("%lf%lf",&h,&l);
    d=((l*l)-(h*h))/(2*h);
    printf("%0.9f",d);
}


#include<stdio.h>
int main()
{
    double h,l,d;
    scanf("%lf %lf",&h,&l);
    d=(((l*l)-(h*h))/(2*h));
    printf("%lf",d);
}


#include<stdio.h>
#include<math.h>
int main()
{
    int h,l;
    double d;
    scanf("%d %d",&h,&l);
    d=(pow(l,2)-pow(h,2))/(2*(double)h);
    printf("%0.9lf",d);
}


#include<stdio.h>
int main()
{
    long long int h,l;
    scanf("%lld%lld",&h,&l);
    double h1=h;
    double l1=l;
    double answer=(l1*l1-h1*h1)/(2*h1);
    printf("%lf",answer);
    return(0);
}


#include<stdio.h>
int main()
{
    long long int h,l;
    scanf("%lld%lld",&h,&l);
    double h1=h;
    double l1=l;
   long double answer=((l*l-h*h)/(2*h1));
    printf("%.13llf",answer);
    return(0);
}