30 lines
433 B
Python
30 lines
433 B
Python
import sys
|
|
input = sys.stdin.readline
|
|
|
|
G, P = int(input()), int(input())
|
|
ans = 0
|
|
parents = [i for i in range(G+1)]
|
|
|
|
def find(x) :
|
|
if x != parents[x] :
|
|
parents[x] = find(parents[x])
|
|
return parents[x]
|
|
|
|
def union(x, y) :
|
|
x = find(x)
|
|
y = find(y)
|
|
|
|
parents[x] = y
|
|
|
|
|
|
for _ in range(P) :
|
|
g = int(input())
|
|
gate = find(g)
|
|
|
|
if gate==0 :
|
|
break
|
|
|
|
union(gate, gate-1)
|
|
ans += 1
|
|
|
|
print(ans) |