问题2914--Business trip

2914: Business trip

[命题人 : ]
时间限制 : 1.000 sec  内存限制 : 64 MB

题目描述

One of oooccc1's friend has found a job, but he will work in the city center. It's far away from school. So he has to take buses(He might change for several buses). He hates to wait for bus, so he asked you to help him find the path that he would change least times. To make the problem easier, all the bus lines only have the start station(S) and end station(E), all the stations are named 1,2,3....N. The bus station near school is 1. oooccc1's friend always starts at 1. There are M different stations at most, and the destination is always at M.

输入

There are multiple test cases. Each test case begin with M,N. M(2<=M<=500) is the destination. N(0<=N<=250000) is the number of buses. then N line follows each line has two integer S and E which indicates that there is a bus line between S and E.

输出

Each test case has one line output contains onr integer which tells the minimal times of transfer. "I'm sorry!" should be print if no matter how many times has he transfered,never would he reach his destination.

样例输入 Copy

3 2
1 2
2 3
4 3
1 2
2 3
3 1

样例输出 Copy

2
I'm sorry!

来源/分类

tyh