n,*a=map(int,open(0).read().split()) from collections import deque a=deque(a) while a and a[-1]==1:a.pop() while a and a[0]==0:a.popleft() print(len(a))