from collections import deque
import sys
N, M = map(int, sys.stdin.readline().split())
data = deque(map(int, sys.stdin.readline().split()))
my_d = deque(range(1, N+1))
idx = 0
ans = 0
for _ in range(M):
find_idx = my_d.index(data[0])
ans += min(abs(find_idx - idx), abs(len(my_d) - abs(find_idx - idx)))
my_d.remove(data[0])
data.popleft()
idx = find_idx
print(ans)
'파이썬 코테 준비' 카테고리의 다른 글
[백준 2110] 공유기 설치 - Python(파이썬) (0) | 2021.02.20 |
---|---|
[백준 5430] AC - Python(파이썬) (0) | 2021.02.15 |
[백준 10866] 덱 - Python(파이썬) (0) | 2021.02.15 |
[백준 1966] 프린터 큐 - Python(파이썬) (0) | 2021.02.15 |
[백준 11866] 요세푸스 문제 0 - Python(파이썬) (0) | 2021.02.15 |
댓글