Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.

One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).

The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).

The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not.

Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.

Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.

Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.


-----Input-----

The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of lessons at the university. 

The second line contains n numbers a_{i} (0 ≤ a_{i} ≤ 1). Number a_{i} equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a_1, a_2, ..., a_{n} are separated by spaces.


-----Output-----

Print a single number — the number of pairs during which Alena stays at the university.


-----Examples-----
Input
5
0 1 0 1 1

Output
4

Input
7
1 0 1 0 0 1 0

Output
4

Input
1
0

Output
0



-----Note-----

In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. 

In the last sample Alena doesn't have a single pair, so she spends all the time at home.

Difficulty: interview

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
c = 0
l = 0
b = 0
while c < len(a) and a[c] == 0:
    c += 1
    b += 1

if c == len(a):
    print(0)
    return

d = len(a) - 1
while a[d] != 1:
    d -= 1
    b += 1

while c <= d:
    if a[c] == 0:
        l += 1
    else:
        if l > 1:
            b += l
        l = 0
    c += 1

print(n - b)

input()
l = list(map(int, input().split()))
while l and l[0] == 0:
	l = l[1:]
while l and l[-1] == 0:
	l = l[:-1]
for i in range(1, len(l) - 1):
	if l[i-1] == 1 and l[i] == 0 and l[i+1] == 1:
		l[i] = 1
print(l.count(1))
		


n = int(input())
mas=list(map(int,input().split(" ")))
p=0
res=0
for i in range(n):
    if mas[i]==0:
        if i>0 and i<n-1:
            if mas[i-1]==1 and mas[i+1]==1:
                mas[i]=1
print(sum(mas))


n=int(input())
l=list(map(int,input().split()))
for i in range(2,n):
    if l[i]==1 and l[i-1]==0 and l[i-2]==1: l[i-1]=1
print(l.count(1))

n = int(input())
a = [int(v) for v in input().split()]

for i in range(1, len(a) - 1):
	if a[i - 1] == 1 and a[i + 1] == 1:
		a[i] = 1

print(sum(a))

n = int(input())
a = list(map(int, input().split()))
count = 0
i = 0
while i < n and a[i] == 0:
    i += 1
while i < n:
    if a[i] == 1:
        i += 1
        count += 1
    else:
        tmp = 0
        while i < n and a[i] == 0:
            tmp += 1
            i += 1
        if i != n and tmp < 2:
            count += tmp
print(count)

n = int(input())

s = input()

a = s.split(" ")

a = [int(i) for i in a]
c = 0
r = 0
for i in range(n):
    if i == n-1:
        if a[i] == 1:
            c += 1
        
    elif r>0:
        if a[i] == 0 and a[i+1] == 0:
            r = 0
        else:
            c += 1
    else:
        if a[i] == 1:
            c += 1
            r = 1
print (c)


input()
pprev, prev = None, None
ans = 0
for i in input().split():
    if i == '1':
        ans += 1
        if prev == '0' and pprev == '1':
            ans += 1
    pprev, prev = prev, i
print(ans)


import sys
import re
sys.stdin.readline()
s = sys.stdin.readline()
s = re.sub('[^01]','',s)
s = s.strip('0')
s = re.sub('0{2,}','',s)
#print(repr(s))
print(len(s))



n = int(input())
a = [int(i) for i in input().split(" ")]
was_one = False;
res = sum(a)
zeros = 0;
for i in a:
	if (i == 1):
		was_one = True
		if (zeros == 1):
			res += 1
		zeros = 0
	if (was_one and i == 0):
		zeros += 1
print(res)

n = int(input())
array = list(map(int, input().split()))
count = sum(array)
for i in range(1, n - 1):
    #if (array[i - 1] == array[i]) and array[i] == 0:
     #   print(i, 'TUTA')
      #  count += 1
    if array[i] == 0 and array[i - 1] == 1 and array[i + 1] == 1:
        count += 1
print(count)


#!/usr/bin/env python
# -*- coding: utf-8 -*-

n = int(input())
A = list(map(int,input().split()))

attends = 0
i = 0
while i < n:
    if A[i] == 1:
        attends += 1
    else:
        if 0 < i < n - 1 and A[i-1] == 1  and A[i+1] == 1:
            attends += 2
            i += 1
    i += 1
print(attends)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import re

N = int(input())
S = input()
S = S.replace(" ", "")
S = S.strip("0")

ret = 0
for seg in re.split("00+", S):
    ret += len(seg)

print(ret)



n = int(input())
lst = [int(x) for x in input().split()]


atuniversity = False
break_length = 0
time = 0

for lesson in lst:
	if lesson == 1:
		atuniversity = True
		break_length = 0
	elif lesson == 0:
		break_length += 1
		if break_length >= 2:
			if atuniversity:
				time -= 1
			atuniversity = False

	if atuniversity:
		time += 1

try:
	if lst[-1] == 0 and lst[-2] == 1:
		time -= 1
except IndexError:
	pass

print(time)

n = int(input())
a = list(map(int, input().split()))

ans = 0
for i, e in enumerate(a):
    if e == 1:
        ans += 1
    else:
        if i < len(a) - 1 and i > 0 and\
         a[i + 1] == 1 and a[i - 1] == 1:
            ans += 1

print(ans)


def read_numbers():
    return list(map(int, input().split()))

def f(pairs):
    while pairs and pairs[0] == 0:
        pairs.pop(0)
    while pairs and pairs[-1] == 0:
        pairs.pop()

    count = 0
    parity = False
    tmp_count = 0
    for i in pairs:
        if i:
            if parity:
                tmp_count += 1
            parity = False
            tmp_count += 1
        else:
            if not parity:
                parity = True
            else:
                count += tmp_count
                tmp_count = 0
            if tmp_count == 0:
                parity = False

    count += tmp_count
    return count



def __starting_point():
    n = int(input())
    numbers = read_numbers()
    print(f(numbers))

__starting_point()

n = int(input())
a = [int(x) for x in input().split()]
k = 0
while k < n and a[k] != 1:
    k += 1
m = n - 1
while m >= 0 and a[m] != 1:
    m -= 1
ans = m - k + 1
for i in range(k + 1, m):
    if a[i] == 0 and (a[i - 1] == 0 or a[i + 1] == 0):
        ans -= 1
print(max(0, ans))

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time

n   = int(input())
a   = [int(i) for i in input().split()]

start = time.time()
ans = 0
i   = 0

while(i < len(a)):
    if a[i] == 1:
        break
    i += 1


while(i < len(a)-1):
    if a[i] == 0 and a[i+1] == 1 and a[i-1] == 1:
        a[i] = 1
        i
    i += 1

print(sum(a))

finish = time.time()
#print(finish - start)


n = int(input())
a = list(map(int, input().split()))
ans = sum(a)
for i in range(1, n - 1):
    if a[i] == 0 and a[i + 1] == 1 and a[i - 1] == 1:
        ans += 1
print(ans)


n = input()
lessons = input().split()
prev = '0'
home = True
cnt = 0
for l in lessons:
    if l == '0' and prev == '0':
        home = True
    elif l == '1':
        cnt += 1
        if prev == '0' and not home:
            cnt += 1
        home = False
    prev = l
print(cnt)




n=int(input())
a=input()
a=a.replace(' ','')
a=a+'00'
c=2
h=0
for i in a:
    if i=='0':
        c+=1
    else:
        if c==1:
            h+=2
        else:
            h+=1
        c=0
print(h)

n = int(input())
a = list(map(int, input().split(' ')[:n]))
res = 0
state = 0
for x in a:
    if state == 0:
        if x == 0:
            pass
        else:
            state = 1
            res += 1
    elif state == 1:
        if x == 0:
            state = 2
        else:
            res += 1
    elif state == 2:
        if x == 0:
            state = 0
        else:
            state = 1
            res += 2

print(res)


n = int(input())
l = list(map(int, input().split()))
cnt = 0
#print(l)
stop = -1
for i in range(n):
    if l[i] == 1:
        break
    else:
        stop = i
while l and l[-1] == 0:
    l.pop(-1)
#print(l)
for i in range(stop+1, len(l)):
    #print(i)
    if i <= len(l)-2:
        if (i<len(l)-1 and l[i] == 0 and l[i+1] == 0) or (i>0 and l[i] == 0 and l[i-1]==0):
            pass
            #print("bob")
        elif l[i] == 1 or l[i+1] == 1 or l[i+2] == 1:
            cnt += 1
            #print("add")
    elif i <= len(l)-2:
        if l[i+1] == 1:
            #print("add")
            cnt += 1
    elif l[i] == 1:
        #print("add")
        cnt += 1
        
print(cnt)


n = int(input())
l = list(map(int, input().split()))
res = 0
for i in range(n):
    if l[i]: res += 1
    elif i > 0 and i < n - 1 and l[i - 1]and l[i + 1]: res += 1
    else: continue
print(res)    


n = int(input())
a = [int(x) for x in input().split()]
time = 0
try:
    start = a.index(1)
except:
    print(0)
    return
current = a[start]
zero_in_row = 0
f = lambda x: 1 if x == 1 else 0

for i in range(start, n):
    if a[i] == 1:
        time += f(zero_in_row)
        zero_in_row = 0
        time += 1
    else:
        zero_in_row += 1

print(time)