Logo
(追記) (追記ここまで)

3229번 - LIFTOVI 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB42252472.727%

문제

Solitaire has N elevators. Each elevator are connecting exactly two floors and it does not stop on the floors between that two floors. The speed of all the elevators are the same, 5 seconds to pass one floor.

On the beginning, each elevator is in its lower position and they are starting cruising to the upper floor. After some elevator come to its upper position, it immediatly starts to go back to its lower position, and so on...

Mirko is on the first (the lowest) floor and he wants as quick as possible come to the top of the solitaire. He can change elevators only on the floors that are common to both elevators, and if the other elevator is in that moment on that floor, that change does not take any time.

Write a program that will calculate minimal time in which Mirko can get to the top of the solitaire.

입력

In the first line of the input file there are two integers K and N, separated with space, number of floors in solitaire and number of elevators, 2 ≤ K ≤ 1000, 1 ≤ N ≤ 50000.

In each of the next N lines there are description of one elevator, two integers A and B, separated with space, 1 ≤ A < B ≤ K, means that elevator is travelling between floors A and B.

There are no two different elevators that travels between same floors.

Note: input data will guarantee that solution will always exists.

출력

In the only line of output file write minimal time (in seconds) from the text above.

제한

예제 입력 1

10 4
1 5
5 10
5 7
7 10

예제 출력 1

45

예제 입력 2

10 3
1 5
3 5
3 10

예제 출력 2

105

예제 입력 3

20 5
1 7
7 20
4 7
4 10
10 20

예제 출력 3

150

힌트

출처

Olympiad > Croatian Highschool Competitions in Informatics > 2003 > Regional Competition - Juniors 4번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /