#include <iostream>
using namespace std;
# include <set>
int main() {
    // your code goes here
    int beg,end,n,m,x=1,a[1000000],i;
    for(i=0;i<1000000;i++)
    a[i]=0;
    cin>>beg>>end;
//  beg++;
//  end++;
    n=beg;
    m=beg;
//  n++;
//  cout<<1<<" ";
    for(i=end+1;i<end+beg+1;i++)
    {
        cout<<i<<" ";
        a[i]++;
    }
//  cout<<a[2];
    for(i=m+end+1;i>=1;i--)
    if(a[i]==0)
    cout<<i<<" ";
    return 0;
}


#include <iostream>
using namespace std;
# include <set>
int main() {
	// your code goes here
	int beg,end,n,m,x=1,a[100010],i;
	for(i=0;i<100010;i++)
	a[i]=0;
	cin>>beg>>end;
//	beg++;
//	end++;
	n=beg;
	m=beg;
//	n++;
//	cout<<1<<" ";
	while(n--)
	{
		cout<<x<<" ";
		a[x]=x;
		x+=beg;
		beg--;
	}
//	cout<<a[2];
	for(i=m+end+1;i>=1;i--)
	if(a[i]==0)
	cout<<i<<" ";
	return 0;
}


#include <iostream>
using namespace std;
# include <set>
int main() {
    // your code goes here
    int beg,end,n,m,x=1,a[1000000],i;
    for(i=0;i<1000000;i++)
    a[i]=0;
    cin>>beg>>end;
//  beg++;
//  end++;
    n=beg;
    m=beg;
//  n++;
//  cout<<1<<" ";
    while(n--)
    {
        cout<<x<<" ";
        a[x]++;
        x+=beg;
        beg--;
    }
//  cout<<a[2];
    for(i=m+end+1;i>=1;i--)
    if(a[i]==0)
    cout<<i<<" ";
    return 0;
}


#include<bits/stdc++.h>

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long

using namespace std;

int a,b,n,p,s[100005];

int main(){
  scanf("%d %d",&a,&b);
  n=a+b+1;
  FI(i,b+1,n) s[++p]=i;
  FD(i,b,1) s[++p]=i;
  FI(i,1,n) printf("%d",s[i],i==n?'\n':' ');
  return 0;
}


#include<bits/stdc++.h>

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long

using namespace std;

int a,b,n,p,s[100005];

int main(){
  scanf("%d %d",&a,&b);
  n=a+b+1;
  FI(i,b+1,n) s[++p]=i;
  FD(i,b,1) s[++p]=i;
  FI(i,1,n) printf("%d%c",s[i],i==n?'\n':' ');
  return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    int a , b ;
    cin>> a >> b ;
    int n=a+b+1;

    if(a)
    {
        cout<< 1 << ' ';
        for(int i=0;i<a;i++)
            cout<< n - a + i + 1 << ' ' ;

        for(int i=0;i<b;i++)
            cout<< n - i - a << ' ' ;
    }

    else
    {
        for(int i=0;i<b+1;i++)
            cout<< (b+1)-i << ' ' ;
    }

    return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
    int a , b ;
    cin>> a >> b ;
    int n=a+b+1;

    if(a)
    {
        cout<< 1 << ' ';
        for(int i=0;i<a;i++)
            cout<< n - a + i + 1 << ' ' ;

        for(int i=0;i<b;i++)
            cout<< i+2 << ' ' ;
    }

    else
    {
        for(int i=0;i<b+1;i++)
            cout<< (b+1)-i << ' ' ;
    }

    return 0;
}


#include <iostream>

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	int n = a + b + 1;
	for (int i = b + 1 ; i <= n ; i++)
		cout << i << ' ';
	for (int i = b ; i >= 2 ; i--)
		cout << i << ' ';
	cout << 1 << endl;
	return 0;
}


#include <iostream>

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	int n = a + b + 1;
	for (int i = b + 1 ; i <= n ; i++)
		cout << i << ' ';
	for (int i = b ; i >= 2 ; i--)
		cout << i << 'i';
	cout << 1 << endl;
	return 0;
}


#include <iostream>

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	int n = a + b + 1;
	for (int i = b + 1 ; i <= n ; i++)
		cout << i << ' ';
	for (int i = b ; i >= 1 ; i--)
		cout << i << ' ';
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stdlib.h>
#include<stdio.h>
#include<stdio.h>
#include<math.h>
using namespace std;
bool used[200000];
int ans[200000];
struct code
{
    int x,y;
};
int main()
{
    int a,b;
    cin>>a>>b;
    int q=a+b+1;
    int n=q;
    int aa;
    if(a!=0)
    aa=n/a;
    int s=1;
    int cnt=0,m=0;
    while(m<=a and a!=0)
    {
        used[s]=1;
        ans[++m]=s;
        s=s+aa;

    }
    if(ans[m]!=n and m!=0)
    {
        ans[m]=n;
        used[n]=true;
    }

    for(int i=1;i<=m;i++) cout<<ans[i]<<" ";
    for(int i=n;i>=1;i--)
    {
        if(used[i]==0)
            cout<<i<<" ";
    }
}


#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stdlib.h>
#include<stdio.h>
#include<stdio.h>
#include<math.h>
using namespace std;
bool used[200000];
int ans[200000];
struct code
{
    int x,y;
};
int main()
{
    int a,b;
    cin>>a>>b;
    int q=a+b+1;
    int n=q;
    int aa;
    if(a!=0)
    aa=n/a;
    int s=1;
    int cnt=0,m=0;

    for(int i=1;i<=a;i++) cout<<i<<" ";
    cout<<n<<" ";
    for(int i=n-1;i>a;i--)
    {
        cout<<i<<" ";
    }
}


#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stdlib.h>
#include<stdio.h>
#include<stdio.h>
#include<math.h>
using namespace std;
bool used[200000];
struct code
{
    int x,y;
};
int main()
{
    int a,b;
    cin>>a>>b;
    int q=a+b+1;
    int n=q;

    int s=1;
    while(s<=q and a!=0)
    {
        used[s]=1;
        cout<<s<<" ";
        s=s+a;
    }
    for(int i=n;i>=1;i--)
    {
        if(used[i]==0)
            cout<<i<<" ";
    }
}


#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<time.h>
#include<math.h>

#define Max(a,b)    (((a) > (b)) ? (a) : (b))
#define Min(a,b)    (((a) < (b)) ? (a) : (b))

#define FOR(i,a,b)  for(i = a; i <= b; i++)
#define ROF(i,a,b)  for(i = a; i >= b; i--)

#define SWAP(a,b)   {t = a; a = b; b = t;}

#define lli long long int

#define endl    puts("")

#define MAX 300000005

int main()
{

	int a, b, s, i;

	scanf("%d %d", &a, &b);

	for(i=b+1; i <= a+b+1; i++)
		printf("%d ", i);

	for(i=b; i >= 1; i--)
		printf("%d ", i);

	return 0;
}


#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<time.h>
#include<math.h>

#define Max(a,b)    (((a) > (b)) ? (a) : (b))
#define Min(a,b)    (((a) < (b)) ? (a) : (b))

#define FOR(i,a,b)  for(i = a; i <= b; i++)
#define ROF(i,a,b)  for(i = a; i >= b; i--)

#define SWAP(a,b)   {t = a; a = b; b = t;}

#define lli long long int

#define endl    puts("")

#define MAX 300000005

int main()
{

	int a, b, s, i;

	scanf("%d %d", &a, &b);

	for(i=b+1; i <= a+b+1; i++)
		printf("%d ", i);

	for(i=b-1; i >= 1; i--)
		printf("%d ", i);

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int i, tek, a, b;

    cin >> a >> b;
    tek = b+1;
    cout << tek << " ";
    for (i=0; i<b; i++)
    {
        tek--;
        cout << tek << " ";
    }
    tek = b+1;
    for (i=0; i<a; i++)
    {
        tek++;
        cout << tek << " ";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int i, tek, a, b;

    cin >> a >> b;
    tek = b;
    cout << tek << " ";
    for (i=0; i<a; i++)
    {
        tek++;
        cout << tek << " ";
    }
    for (i=0; i<b; i++)
    {
        tek--;
        cout << tek << " ";
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int i, tek, a, b;

    cin >> a >> b;
    tek = b+1;
    cout << tek << " ";
    for (i=0; i<b; i++)
    {
        tek--;
        cout << tek << " ";
    }
    for (i=0; i<a; i++)
    {
        tek++;
        cout << tek << " ";
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

#define maxn 3011
#define maxm maxn*maxn
#define pb push_back

int main(){
    int a,b;
    while(cin>>a>>b){
        for(int i=b+1;i>=1;i--)
            cout<<i<<' ';
        for(int i=b+2;i<=a+b+1;i++)
            cout<<i<<' ';
        cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<climits>
using namespace std;
#define pb push_back
#define ll long long
#define mod 1000000007
#define re freopen("in.txt","r",stdin)

int main(){
    int a,b;
    while(cin>>a>>b){
        int st=b*2;
        cout<<st<<' ';
        while(a){
                st++;
            cout<<st<<' ';
//            st++;
            a--;
        }
        while(b){
            b--;
            st--;
            cout<<st<<' ';

        }
                    cout<<endl;
    }
    return 0;
}


#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<climits>
using namespace std;
#define pb push_back
#define ll long long
#define mod 1000000007
#define re freopen("in.txt","r",stdin)

int main(){
    int a,b;
    while(cin>>a>>b){
        int st=b;
        cout<<st<<' ';
        while(a){
                st++;
            cout<<st<<' ';
//            st++;
            a--;
        }
        while(b){
            b--;
            st--;
            cout<<st<<' ';

            cout<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define y1 azaza
#define count ahaha
#define x first
#define y second
#define pb push_back

using namespace std;
string s, st;
ll a[102], n,m,k,mn,mx,up,dw;
char c;
bool f;

int main() {

	cin >> up>> dw;

	n= up+dw+ 1;
	if (up>0){
		cout << 1<<" ";
		for(int i=up-1;i>=0;i--)
			cout << n-i<<" ";
		for(int i=dw;i>=1;i--)
			cout << i+1<<" ";
	}
	else{
		for(int i=n;i>0;i--)
			cout << i<<" ";
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define y1 azaza
#define count ahaha
#define x first
#define y second
#define pb push_back

using namespace std;
string s, st;
ll a[102], n,m,k,mn,mx,up,dw;
char c;
bool f;

int main() {

	cin >> up>> dw;

	n= up+dw+ 1;
	if (up>0){
		cout << 1<<" ";
		for(int i=up-1;i>=0;i--)
			cout << n-i<<" ";
		for(int i=1;i<=dw;i++)
			cout << i+1<" ";
	}
	else{
		for(int i=n;i>0;i--)
			cout << i<<" ";
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define y1 azaza
#define count ahaha
#define x first
#define y second
#define pb push_back

using namespace std;
string s, st;
ll a[102], n,m,k,mn,mx,up,dw;
char c;
bool f;

int main() {

	cin >> up>> dw;

	n= up+dw+ 1;
	if (up>0){
		cout << 1<<" ";
		for(int i=up-1;i>=0;i--)
			cout << n-i<<" ";
		for(int i=1;i<=dw;i++)
			cout << i+1<<" ";
	}
	else{
		for(int i=n;i>0;i--)
			cout << i<<" ";
	}

	return 0;
}


#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int a,b;

    while(~scanf("%d%d",&a,&b)){
        int n=a+b+1;
        for(int i=n-a;i<=n;i++)
        {
            printf("%d ",i);
        }
        for(int i=n-a-1;i>=1;i--)
        {
            printf("%d ",i);
        }
        printf("\n");
    }
}


#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int a,b;

    while(~scanf("%d%d",&a,&b)){
        int n=a+b+1;
        for(int i=n-a;i<=n;i++)
        {
            printf("%d ",i);
        }
        for(int i=1;i<=n-a-1;i++)
        {
            printf("%d ",i);
        }
        printf("\n");
    }
}


#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker,"/STACK:16777216")

#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
#include <iomanip>

#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <algorithm>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <string>
#include <cmath>

using namespace std;

#define X first
#define Y second
#define beg begin()
#define end end()

#define sz size()
#define sl strlen
#define sqr(x) ((int)x*(int)x)
#define cube(x) ((int)x*(int)x*(int)x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define out(a) copy(a.beg,a.end,oit<int>(cout," "))
#define f0n(i,n) for (int i=0;i<(int)n;++i)
#define f1n(i,n) for (int i=1;i<=(int)n;++i)
#define fn0(i,n) for (int i=(int)n-1;i>=0;--i)
#define fn1(i,n) for (int i=(int)n;i>0;--i)
#define fxn(i,x,n) for (int i=(int)x;i<(int)n;++i)
#define fnx(i,n,x) for (int i=(int)n-1;i>=(int)x;--i)
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef std::vector<int> VI;
typedef std::vector<char> VC;
typedef std::vector< vector<int> > VVI;
typedef std::vector< vector<char> > VVC;
typedef std::vector< pair<int,int> > VII;
typedef std::set<int> SI;
typedef std::multiset<int> MSI;
typedef vector<int>::iterator VIit;

#define pb push_back
#define ppb pop_pack
#define mp make_pair
#define stof shrink_to_fit
#define emp emplace
#define empb emplace_back
#define ins insert
#define iter iterator
#define oit ostream_iterator

const double pi=acos(-1.0);
const int INF=1e9+7;

template<typename T>
inline vector<T> getvec(int n) {
    vector<T> tmp(n);
    f0n(i,n)
        cin>>tmp[i];
    return tmp;
}

template<typename T>
inline void MustDie(T tmp) {
    cout<<tmp;
    exit(0);
}

int n,m;

int main() {
    ios_base::sync_with_stdio(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    cin>>n>>m;
    f1n(i,n)
        cout<<i<<' ';
    cout<<n+m+1<<' ';
    fnx(i,n+m+1,n+1)
        cout<<i<<' ';
    exit(0);
}


#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker,"/STACK:16777216")

#include <iostream>
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
#include <iomanip>

#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <algorithm>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <string>
#include <cmath>

using namespace std;

#define X first
#define Y second
#define beg begin()
#define end end()

#define sz size()
#define sl strlen
#define sqr(x) ((int)x*(int)x)
#define cube(x) ((int)x*(int)x*(int)x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define out(a) copy(a.beg,a.end,oit<int>(cout," "))
#define f0n(i,n) for (int i=0;i<(int)n;++i)
#define f1n(i,n) for (int i=1;i<=(int)n;++i)
#define fn0(i,n) for (int i=(int)n-1;i>=0;--i)
#define fn1(i,n) for (int i=(int)n;i>0;--i)
#define fxn(i,x,n) for (int i=(int)x;i<(int)n;++i)
#define fnx(i,n,x) for (int i=(int)n-1;i>=(int)x;--i)
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef std::vector<int> VI;
typedef std::vector<char> VC;
typedef std::vector< vector<int> > VVI;
typedef std::vector< vector<char> > VVC;
typedef std::vector< pair<int,int> > VII;
typedef std::set<int> SI;
typedef std::multiset<int> MSI;
typedef vector<int>::iterator VIit;

#define pb push_back
#define ppb pop_pack
#define mp make_pair
#define stof shrink_to_fit
#define emp emplace
#define empb emplace_back
#define ins insert
#define iter iterator
#define oit ostream_iterator

const double pi=acos(-1.0);
const int INF=1e9+7;

template<typename T>
inline vector<T> getvec(int n) {
    vector<T> tmp(n);
    f0n(i,n)
        cin>>tmp[i];
    return tmp;
}

template<typename T>
inline void MustDie(T tmp) {
    cout<<tmp;
    exit(0);
}

int n,m;

int main() {
    ios_base::sync_with_stdio(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    cin>>n>>m;
    VI a,b;
    f1n(i,max(n,m))
        a.pb(2*i);
    int k=2*max(n,m)-1,i=0;
    while (i<min(n,m)) {
        b.pb(k);
        k-=2;
        ++i;
    }
    if (n>=m) {
        out(a);
        cout<<2*n+1<<' ';
        out(b);
    }
    else {
        reverse(b.beg,b.end);
        out(b);
        cout<<2*m+1<<' ';
        reverse(a.beg,a.end);
        out(a);
    }
    exit(0);
}


#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int n = a + b + 1;
    if(a==0)
    {
        for(int i=n;i>0;i--) cout << i << " ";
        return 0;
    }
    if(b==0)
    {
        for(int i=1;i<=n;i++) cout << i << " ";
        return 0;
    }
    for(int i=0;i<a;i++) cout << i*2+1 << " ";
    if(n%2==0)
    cout << 2*a << " ";
    else cout << 2*a+1 << " ";
    for(int i=b;i>0;i--) cout << i*2 << " ";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int n = a + b + 1;
    if(a==0)
    {
        for(int i=n;i>0;i--) cout << i << " ";
        return 0;
    }
    if(b==0)
    {
        for(int i=1;i<=n;i++) cout << i << " ";
        return 0;
    }
    cout << 1 << " ";
    for(int i=n-a+1;i<=n;i++) cout << i << " ";
    for(int i=n-a;i>1;i--) cout << i << " ";
    return 0;
}


#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<functional>
#define fuck(x) cout<<"["<<x<<"]"
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int>PII;

const int MX = 1e5 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int vis[MX];

int main() {
    int a, b;
    while(~scanf("%d%d", &a, &b)) {
        memset(vis, 0, sizeof(vis));
        int n = a + b + 1, sign = true;
        for(int i = 1; i <= a; i++) {
            printf("%d ", i);
            vis[i] = 1;
        }
        if(!vis[n]) {
            vis[n] = 1;
            printf("%d ", n);
        }
        for(int i = n - 1; i >= 1; i--) {
            if(!vis[i]) printf("%d ", i);
        }
        printf("\n");
    }
    return 0;
}


#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<functional>
#define fuck(x) cout<<"["<<x<<"]"
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int>PII;

const int MX = 1e5 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int main() {
    int a, b;
    int P = 1e5 + 5;
    while(~scanf("%d%d", &a, &b)) {
        printf("%d", P);
        for(int i = 1; i <= a; i++) {
            printf(" %d", P + i);
        }
        for(int i = a - 1; i >= a - b; i--) {
            printf(" %d", P + i);
        }
        printf("\n");
    }
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<sstream>
#include<fstream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#define  FOR(i,x,n) for(int i=x;i<n;i++)
#define rFOR(i,x,n) for(int i=x;i>n;i--)
#define  LFOR(i,x,n) for(long long i=x;i<n;i++)
#define rLFOR(i,x,n) for(long long i=x;i>n;i--)
#define b_e(x) x.begin(),x.end()
#define rb_re(x) x.rbegin(),x.rend()
#define p_b push_back
#define m_p make_pair
#define SZ size()
#define srt insert
#define CL clear()
#define DE delete
#define LL long long
#define S string
#define SS stringstream
#define g_l(x)  getline(cin,x)
#define CIN(x)  scanf("%d",&x)
#define CIN2(x,y) scanf("%d%d",&x,&y)
#define CLN(x)  scanf("%I64d",&x)
#define CLN2(x,y)  scanf("%I64d %I64d",&x,&y)
#define CSN(x)  scanf("100000s",&x)
#define CIUT(x) printf("%d",x)
#define CLUT(x) printf("%I64d",x)
using namespace std;

int main()
{
    int x,y,arr[111111];
    CIN2(x,y);
    for(int i = y+1 ; i <= x+y+1 ; i++)
        cout << i << " ";
    for(int i = y ; i >= 1 ; i--)
        cout << i << " ";
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<sstream>
#include<fstream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#define  FOR(i,x,n) for(int i=x;i<n;i++)
#define rFOR(i,x,n) for(int i=x;i>n;i--)
#define  LFOR(i,x,n) for(long long i=x;i<n;i++)
#define rLFOR(i,x,n) for(long long i=x;i>n;i--)
#define b_e(x) x.begin(),x.end()
#define rb_re(x) x.rbegin(),x.rend()
#define p_b push_back
#define m_p make_pair
#define SZ size()
#define srt insert
#define CL clear()
#define DE delete
#define LL long long
#define S string
#define SS stringstream
#define g_l(x)  getline(cin,x)
#define CIN(x)  scanf("%d",&x)
#define CIN2(x,y) scanf("%d%d",&x,&y)
#define CLN(x)  scanf("%I64d",&x)
#define CLN2(x,y)  scanf("%I64d %I64d",&x,&y)
#define CSN(x)  scanf("100000s",&x)
#define CIUT(x) printf("%d",x)
#define CLUT(x) printf("%I64d",x)
using namespace std;

int main()
{
    int x,y,arr[111111];
    CIN2(x,y);
    for(int i = y ; i < x+y+1 ; i++)
        cout << i+1 << " ";
    for(int i = 0 ; i < y ; i++)
        cout << i+1 << " ";
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 1000000000
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b ;
    int n = a+b+1;
    bool visit[n+1];
    int N = n ;
    memset(visit,false,sizeof visit);
    for(int i = 0;i<b;i++){
        visit[n-1] = true;
        n--;
    }
    for(int i = 1 ; i <= N ;i++){
        if(!visit[i])cout << i << " " ;
    }
    for(int i = N-1 ; i >=0 ;i--){
        if(visit[i])cout << i << " " ;
    }
    return 0;

}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 1000000000
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b ;
    int n = a+b+1;
    bool visit[n+1];
    int N = n ;
    memset(visit,false,sizeof visit);
    for(int i = 0;i<b;i++){
        visit[n-1] = true;
        n--;
    }
    for(int i = 1 ; i <= N ;i++){
        if(!visit[i])cout << i << " " ;
    }
    for(int i = 0 ; i < N ;i++){
        if(visit[i])cout << i << " " ;
    }
    return 0;

}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 1000000000
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b ;
    if(a==0 && b==0){
            cout << "0";
            return 0;
    }
    int n = a+b+1;
    bool visit[n+1];
    int N = n ;
    memset(visit,false,sizeof visit);
    for(int i = 0;i<b;i++){
        visit[n-1] = true;
        n--;
    }
    for(int i = 1 ; i <= N ;i++){
        if(!visit[i])cout << i << " " ;
    }
    for(int i = 0 ; i < N ;i++){
        if(visit[i])cout << i << " " ;
    }
    return 0;

}


#include<iostream>
#include<vector>
#include<new>
#include<array>
#include<algorithm>
#include<cstdbool>
using namespace std;
int ans[1000005];
bool used[1000005];
int main()
{
    int A;
    int B;
    cin >> A >> B;
    int N = A + B + 1;
    ans[A + 1] = N;
    used[N] = true;
    for (int i = 1; i <=A; i++)
        if (i == A)
        {
            ans[i] = N - 1;
            used[N - 1] = true;

        }
        else
        {
            ans[i] = i;
            used[i] = true;
        }
    int p = A + 2;
    int u = N;
    for (int i = 1; i <= B; i++)
    {
        while (used[u])
            u--;
        ans[p++] = u;
    }
    for (int i = 1; i <= N; i++)
        cout << ans[i] << ' ';
    return 0;
}


#include<iostream>
using namespace std;
int ans[1000005];
bool used[1000005];
int main()
{
    int A;
    int B;
    cin >> A >> B;
    int N = A + B + 1;
    ans[A + 1] = N;
    used[N] = true;
    for (int i = 1; i <=A; i++)
        if (i == A)
        {
            ans[i] = N - 1;
            used[N - 1] = true;

        }
        else
        {
            ans[i] = i;
            used[i] = true;
        }
    int p = A + 2;
    int u = N;
    for (int i = 1; i <= B; i++)
    {
        while (used[u])
            u--;
        ans[p++] = u;
    }
    for (int i = 1; i <= N; i++)
        cout << ans[i] << ' ';
    return 0;
}


#include<iostream>
#include<cstring>
#include<vector>
#include<new>
#include<array>
#include<algorithm>
#include<cstdbool>
using namespace std;
int ans[1000005];
bool used[1000005];
int main()
{
	int A;
	int B;
	cin >> A >> B;
	int N = A + B + 1;
	ans[A + 1] = N;
	used[N] = true;
	for (int i = 1; i <=A; i++)
		if (i == A)
		{
			ans[i] = N - 1;
			used[N - 1] = true;

		}
		else
		{
			ans[i] = i;
			used[i] = true;
		}
	int p = A + 2;
	int u = N;
	for (int i = 1; i <= B; i++)
	{
		while (used[u])
			u--;
		ans[p++] = u;
	}
	for (int i = 1; i <= N; i++)
		cout << ans[i] << ' ';
	return 0;
}


#include<iostream>
using namespace std;
int ans[1000005];
bool used[1000005];
int main()
{
    int A;
    int B;
    cin >> A >> B;
    int N = A + B + 1;
    ans[A + 1] = N;
    used[N] = true;
    for (int i = 1; i <=A; i++)
        if (i == A)
        {
            ans[i] = N - 1;
            used[N - 1] = true;

        }
        else
        {
            ans[i] = i;
            used[i] = true;
        }
    int p = A + 2;
    int u = N;
    for (int i = 1; i <= B; i++)
    {
        while (used[u])
            u--;
        ans[p++] = u;
        used[u] = true;
    }
    for (int i = 1; i <= N; i++)
        cout << ans[i] << ' ';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, m;

int main()
{
	cin >> n >> m;

	for (int i = (n+m+1)-n; i <= n+m+1; i++) {
		cout << i << ' ';
	}
	for (int i = (n+m)-n; i >= 1; i--) {
		cout << i << ' ';
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, m;

int main()
{
	cin >> n >> m;

	for (int i = (n+m+1)-n; i <= n+m+1; i++) {
		cout << i << ' ';
	}
	for (int i = 1; i < (n+m+1)-n; i++) {
		cout << i << ' ';
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, m;

int main()
{
	cin >> n >> m;

	for (int i = (n+m+1)-n; i <= n+m+1; i++) {
		cout << i << ' ';
	}
	for (int i = (n+m+1)-n; i >= 1; i--) {
		cout << i << ' ';
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n , m ,tmp;
    cin >> n >> m;
    tmp = n+m+1;
    if (n > m){
        cout << 1 << ' ';
    for (int x = 2 , i = tmp; x <= tmp; x++ , i--)
    {
        if (m != 0 )
            cout << i << ' ' , m--;
        if (n != 0 )
            cout << x << ' ' , n--;
    }
    }
    else if (m > n)
    {
    cout << tmp << ' ';
    for (int x = 1 , i = tmp-1; x <= tmp; x++ , i--)
    {
         if (m != 0 )
            cout << i << ' ' , m--;
        if (n != 0)
            cout << x << ' ' , n--;
    }
    }
    else
    {
        cout << 1 << ' ';
    for (int x = 2 , i = tmp; x <= tmp; x++ , i--)
    {
         if (m != 0 )
            cout << i << ' ' , m--;
        if (n != 0)
            cout << x << ' ' , n--;
    }

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n , m ,tmp;
    cin >> n >> m;
    tmp = n+m+1;
    if (n > m){
        cout << 1 << ' ';
    for (int x = 2 , i = tmp; x <= tmp; x++ , i--)
    {
        if (m != 0 )
            cout << i << ' ' , m--;
        if (n != 0 )
            cout << x << ' ' , n--;
    }
    }
    else
    {
    cout << tmp << ' ';
    for (int x = 1 , i = tmp-1; x <= tmp; x++ , i--)
    {
         if (m != 0 )
            cout << i << ' ' , m--;
        if (n != 0)
            cout << x << ' ' , n--;
    }
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n , m ,tmp;
    cin >> n >> m;
    tmp = n+m+1;
    if (n > m){
        cout << 1 << ' ';
    for (int x = 2 , i = tmp; x <= tmp; x++ , i--)
    {
        if (m != 0 )
            cout << i << ' ' , m--;
        if (n != 0 )
            cout << x << ' ' , n--;

    }
    }
    else
    {
    cout << tmp << ' ';
    for (int x = 1 , i = tmp-1; x <= tmp; x++ , i--)
    {
         if (m != 0 )
            cout << i << ' ' , m--;
        if (n != 0)
            cout << x << ' ' , n--;
    }
    }
    return 0;
}


#include<cstdio>
int a,b,n,i;
int main ()
{
//freopen("491.in","r",stdin);
//freopen("491.out","w",stdout);
scanf("%d%d",&a,&b);
n=a+b+1;
if(a!=0)
    {
    printf("1 ");
    for(i=1;i<=a;i++)
        printf("%d ",1+i+b);
    for(i=1;i<=b;i++)
        printf("%d ",b-i+2);
    }
else
    for(i=n;i>=1;i--)
        printf("%d ",i);
return 0;
}


#include<cstdio>
int a,b,n,i;
int main ()
{
//freopen("491.in","r",stdin);
//freopen("491.out","w",stdout);
scanf("%d%d",&a,&b);
n=a+b+1;
if(a!=0)
    {
    printf("1 ");
    for(i=1;i<=a;i++)
        printf("%d ",2+i);
    for(i=1;i<=b;i++)
        printf("%d ",b-i+2);
    }
else
    for(i=n;i>=1;i--)
        printf("%d ",i);
return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main(){
    int i,a,b,n;
    scanf("%d %d",&a,&b);
    n = a + b + 1;

    for(i = 1 ; i <= n ; i++){
        printf("%d ",i);
    }

    return 0;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main(){
    int i,a,b,n;
    scanf("%d %d",&a,&b);
    n = a + b + 1;

    for(i = n - a ; i <= n ; i++){
        printf("%d ",i);
    }
    for(i = n - a - 1 ; i >= 1 ; i--){
        printf("%d ",i);
    }

    return 0;
}


#include <iostream>
using namespace std;

	int main() {
		int a,b;
		cout <<"Write a ";
		cin >> a;	//9
		cout <<"Write b ";
		cin >> b;	//1
		int n=a+b+1;	//11
		//2 3 4 5 6 7 8 9 10 11 1
		for(int i=n-a;i<=n;i++) cout << i << " ";
		for(int i=b;i>=1;i--) cout << i << " ";
		}


#include <iostream>
using namespace std;

	int main() {
		int a,b;
		cin >> a;	//9
		cin >> b;	//1
		int n=a+b+1;	//11
		//2 3 4 5 6 7 8 9 10 11 1
		for(int i=n-a;i<=n;i++) cout << i << " ";
		for(int i=b;i>=1;i--) cout << i << " ";
		}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int n=a+b+1;
    int p;
    for( p=n-a;p<=n;p++) printf("%d ",p);
    for( int i=1;i<=n-a-1;i++) printf("%d ",i);

}

/*

*/


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int n=a+b+1;
    int p;
    for( p=n-a;p<=n;p++) printf("%d ",p);
    for( int i=n-a-1;i>=1;i--) printf("%d ",i);

}

/*

*/


#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#include<cstring>
#include<cmath>
#include<map>
#define eps 1e-10
#define INF 1<<30
using namespace std;
#define maxn 100005

using namespace std;

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    int n=1+b+a;
    if(a==0)
    {
        for(int i=n;i>=1;i--)
            printf("%d%c",i,i==1?'\n':' ');
    }
    else if(b==0){
        for(int i=1;i<=n;i++)
            printf("%d%c",i,i==n?'\n':' ');
    }
    else{
        for(int i=1;i<a;i++)
        {
            printf("%d ",i);
        }
        for(int i=n;i>=a;i--)
        {
            printf("%d%c",i,i==a?'\n':' ');
        }
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#include<cstring>
#include<cmath>
#include<map>
#define eps 1e-10
#define INF 1<<30
using namespace std;
#define maxn 100005

using namespace std;

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    int n=1+b+a;
    if(a==0)
    {
        for(int i=n;i>=1;i--)
            printf("%d%c",i,i==1?'\n':' ');
    }
    else if(b==0){
        for(int i=1;i<=n;i++)
            printf("%d%c",i,i==n?'\n':' ');
    }
    else{
        for(int i=1;i<=a;i++)
        {
            printf("%d ",i);
        }
        for(int i=n;i>a;i--)
        {
            printf("%d%c",i,i==a?'\n':' ');
        }
    }
    return 0;
}


#include <iostream>
using namespace std;

int A, B, N;

int main() {

	cin >> A >> B;
	N = A + B + 1;

	if(A == 0) {
	   for(int i = N; i >= 1; i--) cout<<i<<" ";
	   cout<<endl;
	}
	else if (B == 0) {
	   for(int i = 1; i <= N; i++) cout<<i<<" ";
	   cout<<endl;
	}
	else {
		cout<<"1 ";
		for(int i = N - A + 1; i <= N; i++) cout<<i<<" ";
		for(int i = N - A; i >= 2; i--) cout<<i<<" ";
		cout<<endl;
	}

	return 0;
}


#include <iostream>
using namespace std;

int A, B, N;

int main() {

	cin >> A >> B;
	N = A + B + 1;

	cout<<A<<" "<<B<<endl;
	if(A == 0) {
	   for(int i = N; i >= 1; i--) cout<<i<<" ";
	   cout<<endl;
	}
	else if (B == 0) {
	   for(int i = 1; i <= N; i++) cout<<i<<" ";
	   cout<<endl;
	}
	else {
		cout<<"1 ";
		for(int i = N - A + 1; i <= N; i++) cout<<i<<" ";
		for(int i = N - A; i >= 2; i--) cout<<i<<" ";
		cout<<endl;
	}

	return 0;
}


#include <iostream>

using namespace std;

int A,B;

int main()
{

      cin >> A >> B;

      if (A==0) for (int i = B+1; i >= 1; i--) cout << i << " ";
      else
      if (B==0) for (int i = 1; i <= A+1; i++) cout << i << " ";
      else
      {
         cout << "1 ";
         for (int i = 1; i <= A; i++) cout << i+B+1 << " ";
         for (int i = B; i >= 1; i--) cout << i+1 << " ";
      }

      return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int A,B,N;

	cin >> A >> B;

	N = A+B+1;

	int s[100000];

	if (A>B)
	{
		for (int i = 0; i < N; i++) s[i] = i+1;

	        int Btmp;

                if (B!=0)
                {
                Btmp = 0;

		for (int i = 1; i < N-1; i+=2)
		{
			swap(s[i], s[i+1]);
			Btmp++;
			if (Btmp==B) break;
		}
                }
	}
	else
	{
		for (int i = 0; i < N; i++) s[i] = N-i;

                if (A!=0)
                {
                int Atmp;

		Atmp = 0;
		for (int i = 0; i < N; i++) s[i] = i+1;

		for (int i = 1; i < N-1; i+=2)
		{
			swap(s[i], s[i+1]);
		        Atmp++;
		 	if (Atmp==B) break;
                }
                }
	}

	for (int i = 0; i < N; i++) cout << s[i] << " ";

        cout << endl;

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int A,B,N;

	cin >> A >> B;

	N = A+B+1;

	int s[100000];

	if (A>B)
	{
		for (int i = 0; i < N; i++) s[i] = i+1;

	        int Btmp;

                if (B!=0)
                {
                Btmp = 0;

		for (int i = 1; i < N-1; i+=2)
		{
			swap(s[i], s[i+1]);
			Btmp++;
			if (Btmp==B) break;
		}
                }
	}
	else
	{
		for (int i = 0; i < N; i++) s[i] = N-i;

                if (A!=0)
                {
                int Atmp;

		Atmp = 0;
		for (int i = 0; i < N; i++) s[i] = i+1;

		for (int i = 1; i < N-1; i+=2)
		{
			swap(s[i], s[i+1]);
		        Atmp++;
		 	if (Atmp==A) break;
                }
                }
	}

	for (int i = 0; i < N; i++) cout << s[i] << " ";

        cout << endl;

	return 0;
}


#include <iostream>

using namespace std;

int A,B;

int main()
{

      cin >> A >> B;

      if (A==0) for (int i = B+1; i >= 1; i--) cout << i << " ";
      else
      if (B==0) for (int i = 1; i <= A+1; i++) cout << i << " ";
      else
      {
         cout << "1 ";
         for (int i = 1; i <= A; i++) cout << i+B+1;
         for (int i = B; i >= 1; i--) cout << i+1;
      }

      return 0;
}


#include <cstdio>int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for (int i=0;i<a+1;i++) printf("%d ",b+i+1);
	for (int i=0;i<b;i++) printf("%d ",b-i);}


#include <cstdio>
using namespace std;
int main(){
	int a,b;//return 0;
	scanf("%d%d",&a,&b);
	for (int i=0;i<a+1;i++) printf("%d ",b+i+1);
	for (int i=0;i<b;i++) printf("%d ",b-i);}


#include <iostream>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
for(int i=0; i<m+n;i++)
if(i<n) cout <<m+i<<" ";
else if (i==n)
cout<<m+n+1<<" ";
else cout<<m+n-i<<" ";
return 0;
}


#include <iostream>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
for(int i=0; i<=m+n;i++)
if(i<n) cout <<m+i+1<<" ";
else if (i==n)
cout<<m+n+1<<" ";
else cout<<m+n-i+1<<" ";
return 0;
}


#include <iostream>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
for(int i=0; i<m+n;i++)
if(i<n) cout <<i+1<<" ";
else if (i==n)
cout<<m+n+1<<" ";
else cout<<i+1<<" ";
return 0;
}


#include<stdio.h>
int a,b,n,st,i;main(){scanf("%d %d",&a,&b);n=a+b+1;st=n-a;for(i=0;i<=a;i++)printf("%d ",st+i);for(i=1;i<=b;i++)printf("%d ",st-i);}


#include<stdio.h>
int a,b,n,st,i;
int main() {

	scanf("%d %d",&a,&b);
	n=a+b+1;

	st=n-a;

	for(i=0 ; i<=a ; i++)
		printf("%d ",st+i);

	for(i=1 ; i<=b ; i++)
		printf("%d ",st-i);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,n;
    cin>>a>>b;
    n=a+b+1;
    for(int i=b+1;i<=n;i++)
        cout<<i<<" ";
    for(int i=b;i>=1;i--)
        cout<<i<<" ";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b;
    c=a+b+1;
    for(int i=1;i<=c;i++)
        cout<<i<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,n;
    cin>>a>>b;
    n=a+b+1;
    for(int i=b+1;i<=n;i++)
        cout<<i<<" ";
    for(int i=b;i>=1;i--)
        cout<<b<<" ";
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a,b,n;

    cin>>a;
    cin>>b;

    n=a+b+1;

    int c[n];

    for(int i=1;i<=n;i++)
        c[i]=i;

    for(int i=1;i<=a;i++)
    {
        cout<<c[i]<<" ";
    }

    cout<<c[n]<<" ";

    for(int i=a+1;i<n;i++)
        cout<<c[i]<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ll a,b,n;

    cin>>a;
    cin>>b;

    n=a+b+1;

    ll c[n];

    for(int i=1;i<=n;i++)
        c[i]=i;

    for(int i=1;i<=a;i++)
    {
        cout<<c[i]<<" ";
    }

    cout<<c[n]<<" ";

    for(int i=a+1;i<n;i++)
        cout<<c[i]<<" ";

        cout<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ll a,b,n;

    cin>>a;
    cin>>b;

    n=a+b+1;

    ll c[n];

    for(int i=1;i<=n;i++)
        c[i]=i;

    for(int i=1;i<=a;i++)
    {
        cout<<c[i]<<" ";
    }

    cout<<c[n]<<" ";

    for(int i=n-1;i>=a+1;i--)
        cout<<c[i]<<" ";

        cout<<endl;

    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <set>
#include <sstream>
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<=(b); i++)
#define FR(i,b) for(int i=0; i<(b);i++)
#define DOWN(i,a,b) for(int i=(a); i >=(b); i--)
#define X first
#define Y second
using namespace std;
const int maxn=1000*100+10;
int m,n,x,y,a[maxn];
bool avail[maxn];
int main() {
    std::ios::sync_with_stdio(false);
//    freopen("input.inp","r",stdin);
    //freopen("output.out","w",stdout);
    cin >> x >> y;
    memset(avail,true,sizeof(avail));
    n=x+y+1;
    m=n;
    if (y!=0) {
        a[1]=m;
        FOR(i,1,y-1) {
            a[i+1]=m;
            avail[m]=false;
            m--;
        }
        a[y+1]=1;
        avail[1]=false;
    }
    m=2;
    FOR(i,y+2,n) {
        a[i]=m;
        m++;
    }
    FOR(i,1,n) cout << a[i] <<' ';

    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <set>
#include <sstream>
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<=(b); i++)
#define FR(i,b) for(int i=0; i<(b);i++)
#define DOWN(i,a,b) for(int i=(a); i >=(b); i--)
#define X first
#define Y second
using namespace std;
const int maxn=1000*100+10;
int m,n,x,y,a[maxn];
bool avail[maxn];
int main() {
    std::ios::sync_with_stdio(false);
//    freopen("input.inp","r",stdin);
    //freopen("output.out","w",stdout);
    cin >> x >> y;
    memset(avail,true,sizeof(avail));
    n=x+y+1;
    m=n;
    if (y!=0) {
        a[1]=m;
        m--;
        FOR(i,1,y-1) {
            a[i+1]=m;
            avail[m]=false;
            m--;
        }
        a[y+1]=1;
        avail[1]=false;
    }
    else a[1]=1;
    m=2;
    FOR(i,y+2,n) {
        a[i]=m;
        m++;
    }
    FOR(i,1,n) cout << a[i] <<' ';

    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <set>
#include <sstream>
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<=(b); i++)
#define FR(i,b) for(int i=0; i<(b);i++)
#define DOWN(i,a,b) for(int i=(a); i >=(b); i--)
#define X first
#define Y second
using namespace std;
const int maxn=1000*100+10;
int m,n,x,y,a[maxn];
bool avail[maxn];
int main() {
    std::ios::sync_with_stdio(false);
//    freopen("input.inp","r",stdin);
    //freopen("output.out","w",stdout);
    cin >> x >> y;
    memset(avail,true,sizeof(avail));
    n=x+y+1;
    m=n;
    if (y!=0) {
        a[1]=m;
        m--;
        FOR(i,1,y-1) {
            a[i+1]=m;
            avail[m]=false;
            m--;
        }
        a[y+1]=1;
        avail[1]=false;
    }
    m=2;
    FOR(i,y+2,n) {
        a[i]=m;
        m++;
    }
    FOR(i,1,n) cout << a[i] <<' ';

    return 0;
}


#include<bits/stdc++.h>

#define SZ(S) (int)S.size()
#define MEM(X,XX) memset(X,XX,sizeof(X))

/**    LAST STAND   **/

#define READ(s) freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)

using namespace std ;

int arr[100005][2] ;
int main()
{
   // READ("test.txt") ;
    int n , m , c , h , a , b , in ;
    cin >> n >> m >> c ;
    for(int i=0 ; i<c ; i++)
        cin >> arr[i][0] >> arr[i][1] ;

    long long mini = 1e18 ;

    cin >> h ;
    for(int i=0 ; i<h ; i++)
    {
        cin >> a >> b ;

        long long maxi = -1e18 ;
        for(int j=0 ; j<c ; j++)
        {
            long long tmp = abs(a-arr[j][0]) + abs(b-arr[j][1]) ;
            maxi = max(maxi,tmp) ;
        }
//        cout << i << " " << maxi << " " << mini << endl ;

        if( mini > maxi )
          mini = maxi , in = i ;

    }
    cout << mini << endl << in+1 ;

}


#include<bits/stdc++.h>

#define SZ(S) (int)S.size()
#define MEM(X,XX) memset(X,XX,sizeof(X))

/**    LAST STAND   **/

#define READ(s) freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)

using namespace std ;

int main()
{

    int a , b ;
    cin >> a >> b ;

    MEM(arr,0) ;

    int in = b + 1 ;
    while( in <= a+b+1 )
        cout << in << " " , in++ ;

    in = b ;
    while( in > 0 )
        cout << in << " " , in-- ;

}


#include<bits/stdc++.h>

#define SZ(S) (int)S.size()
#define MEM(X,XX) memset(X,XX,sizeof(X))

/**    LAST STAND   **/

#define READ(s) freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)

using namespace std ;

int main()
{

    int a , b ;
    cin >> a >> b ;

    int in = b + 1 ;
    while( in <= a+b+1 )
        cout << in << " " , in++ ;

    in = b ;
    while( in > 0 )
        cout << in << " " , in-- ;

}


#include<bits/stdc++.h>

#define SZ(S) (int)S.size()
#define MEM(X,XX) memset(X,XX,sizeof(X))

/**    LAST STAND   **/

#define READ(s) freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)

using namespace std ;

bool arr[100005] ;
int main()
{

    int a , b , cp , c ;
    cin >> a >> b ;

    MEM(arr,0) ;

    c = a + b + 1 , cp = (a>0) ? a-1 : c ;
    while( a <= c && a > 0 )
        cout << a << " " , a++ ;

    while( cp > 0 )
        cout << cp << " " , cp-- ;

}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

ll dp[5010][5010];

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<ll> v(n);rep(i,0,n)cin>>v[i];

  rep(i,0,5010)rep(j,0,5010)dp[i][j]=LINF;
  dp[0][n]=0;

  rep(i,0,n){
    if(v[i]>0)chmin(dp[i+1][i],dp[i][n]+1);
    chmin(dp[i+1][n],dp[i][n]+int(v[i]>0));

    rep(j,0,i){
      if(v[i]>v[j])chmin(dp[i+1][j],dp[i][j]+1);
      else if(v[i]==v[j])chmin(dp[i+1][j],dp[i][j]);
      else {
        chmin(dp[i+1][i],dp[i][j]+1);//new op1
        chmin(dp[i+1][n],dp[i][j]+1);
      }
    }

  }

  ll ans=LINF;
  rep(i,0,n+1)chmin(ans,dp[n][i]);
  cout<<ans<<ENDL;
}
//! ( . _ . ) !
//CHECK overflow,vector_size,what to output?


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

template <typename T,typename IND>
vector<T> dijkstra(int s,vector<vector<pair<IND, T> > > & G){
  using Pa = pair<T, IND>;
  vector<T> D(G.size(),LINF);//----------------
  queue<Pa> q;
  D[s]=0;
  q.emplace(D[s],s);//最短距離、ゴール頂点番号

  while(!q.empty()){
    T spath=q.front().first;
    int v=q.front().second;
    q.pop();

    if(D[v]<spath) continue;
    for(auto& e:G[v]){
      int u=e.first;//頂点番号
      T c=e.second;//最短距離
      if(D[u]>D[v]+c){
        D[u]=D[v]+c;
        q.emplace(D[u],u);
      }
    }
  }
  return D;
}

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);

  ll n;cin>>n;
  V<ll> v(n);rep(i,0,n)cin>>v[i];

  VV<PL> e(n+2,V<PL>(0));

  ll mn,mnnum,cost;
  rep(i,0,n){
    mn=INF,mnnum=1,cost=0;
    rep(j,i,n){
      if(chmin(mn,v[j])){
        cost+=mnnum;
        mnnum=1;
      }else if(mn<v[j]){
        ++cost;
      }else{
        ++mnnum;
      }

      if(cost>j-i+1)continue;

      e[i].eb(j+1,cost);
    }
  }
  v.clear();

  V<ll> ans=dijkstra(0,e);
  cout<<ans[n-1]<<ENDL;
}
//! ( . _ . ) !
//CHECK overflow,vector_size,what to output?


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

template<typename T,typename Y,T(F_up)(T,T),Y(F_gt)(T,Y)>
struct BUPSegTree{
    int sz,ex;
    T ini_d;
    vector<T> dat;

    BUPSegTree(vector<T> init,T _ini_d) : ini_d(_ini_d){
        int n=(int)(init.size());
        ex=1;
        while((1<<ex) < n)ex++;
        sz=(1<<ex);
        dat=vector<T>(2*sz,ini_d);
        for (int i = 0; i < n; ++i) dat[sz + i] = init[i];
        for (int i = sz - 1; i > 0; --i) dat[i] = F_up(dat[2*i],dat[2*i+1]);
    }

    void up_q(int p,T x){
        for(dat[p+=sz]=x;p>1;p>>=1){//+=にすると一点加算
            dat[p>>1]=F_up(dat[p],dat[p^1]);
        }
    }

    T get_q(int l,int r){//[l,r)
        T res=ini_d;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1){
                res=F_gt(res,dat[l]);
                ++l;
            }
            if(r&1){
                --r;
                res=F_gt(res,dat[r]);
            }
        }
        return res;
    }
};
//0-indexedと思って渡してよい
PL my_min(PL a,PL b){return min(a,b);}

BUPSegTree<PL,PL,my_min,my_min> seg(V<PL>(2),{INF,INF});

V<PL> v;

ll solve(int l,int r,ll sub){//[l,r]
  //debug(l,r);
  if(l>r)return 0;
  if(l==r){
    return ll(v[l].fs!=sub);
  }

  ll mn,mnind;
  tie(mn,mnind)=seg.get_q(l,r+1);

  if(mn==sub)return solve(l,mnind-1,sub)+solve(mnind+1,r,sub);
  else{
    return solve(l,mnind-1,mn)+1+solve(mnind+1,r,mn);
  }
}

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  v.resize(n);
  rep(i,0,n){
    cin>>v[i].fs;
    v[i].sc=i;
  }

  seg=BUPSegTree<PL,PL,my_min,my_min>(v,{INF,INF});

  cout<<solve(0,n-1,0)<<ENDL;

}
//! ( . _ . ) !
//CHECK overflow,vector_size,what to output?


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

ll dp[5010][5010];

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<ll> v(n);rep(i,0,n)cin>>v[i];

  rep(i,0,5010)rep(j,0,5010)dp[i][j]=LINF;
  dp[0][n]=0;

  rep(i,0,n){
    if(v[i]>0)chmin(dp[i+1][i],dp[i][n]+1);
    chmin(dp[i+1][n],dp[i][n]+int(v[i]>0));

    rep(j,0,i){
      if(v[i]>v[j])chmin(dp[i+1][j],dp[i][j]+1);
      else if(v[i]==v[j])chmin(dp[i+1][j],dp[i][j]);
      else {
        chmin(dp[i+1][i],dp[i][j]+1);//new op1
        chmin(dp[i+1][n],dp[i][j]+int(v[i]>0));
      }
    }

  }

  ll ans=LINF;
  rep(i,0,n+1)chmin(ans,dp[n][i]);
  cout<<ans<<ENDL;
}
//! ( . _ . ) !
//CHECK overflow,vector_size,what to output?


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
pvi lookup(int l,int r){
	int mini = INT_MAX; ll* bits = new ll[80]; for(int i=0;i<80;i++) bits[i]=0LL;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini) {
		bits[i/64] = bits[i/64] | (1LL<<(i%64));
	}
	return mp(bits,mini);
}
ll divide(int l,int r,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	auto mm = lookup(l,r);
	int ori_n=0;
	for(int i=0;i<ncap;i++){
		int x = mm.first[i];
		while(x>0){
			x-=x&(-x); ori_n++;
		}
	}
	ll tot=0; int start=l-1;
	int end=0;
	for(int i=0;i<ncap;i++){
		ll x = mm.first[i];
		while(x>0){
			ll pos = x&(-x);
			end = (i*64) + (int)log2(pos);
			tot += divide(start+1,end-1,ncap);
			start = end;
			x -= pos;
		}
	}
	delete mm.first;
	if(start < r){
		tot += divide(start+1,r,ncap);
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,(int)(ceil((double)n/64)));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
ll divide(int l,int r,int neg){
	if(l>r) return 0LL; if(l==r)return arr[l]==0?0LL:1LL;
	int ori_n=0;
	////
	ll tot=0; int start=l-1;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini){
		tot += divide(start+1,i-1,neg);
		start = i;
	}
	////
	if(start < r){
		tot += divide(start+1,r,neg);
	}
	return min(mini-neg+tot,(ll)(r-l+1));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,0);
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
//typedef pair<set<int>,int> pvi;
typedef long long ll;
typedef pair<ll*,int> pvi;

class ST{
	public:
		int icap;
		int n;
		int height;
		pvi* tree;
		int left_child(int i){return i*2+1;}
		int right_child(int i){return i*2+2;}
		pvi get_minimum_update(pvi current,pvi other){
			if(current.second==other.second){
    			//current.first.insert(other.first.begin(), other.first.end());
    			for(int i=0;i<icap;i++) current.first[i] = current.first[i]|other.first[i];
    			if(other.second==INT_MAX) delete other.first;
				return current;
			}
			if(current.second>other.second){
				if(current.second==INT_MAX) delete current.first;
				return other;
			}
			if(other.second==INT_MAX) delete other.first;
			return current;
		}
		pvi get_minimum_lookup(pvi current,pvi other){
			if(current.second==other.second){
    			//current.first.insert(other.first.begin(), other.first.end());
    			for(int i=0;i<icap;i++) current.first[i] = current.first[i]|other.first[i];
				return current;
			}
			if(current.second>other.second){
				return other;
			}
			return current;
		}
		ST(int _n){
			n = _n; icap = (int)ceil((double)n/64);
			height = (int)(ceil(log2(n)));
			tree = new pvi[2*(1<<height)-1];
			//for(int i=0;i<(2*(1<<height)-1);i++) tree[i]=mp(set<int>(),INT_MAX);
			for(int i=0;i<(2*(1<<height)-1);i++){
				ll* _bits = new ll[icap+1]; for(int j=0;j<icap;j++) _bits[j]=0LL;
				tree[i]=mp(_bits,INT_MAX);
			}
		}
		pvi recur_update(int l,int r,int i,int v,int curr){
			if(l==r){
//				set<int> vp; vp.insert(i);
//				tree[curr] = mp(vp,v);
				tree[curr].first[i/64] = tree[curr].first[i/64] | (1LL<<(i%64));
				tree[curr].second = v;
				return tree[curr];
			}
			int mid = l+(r-l)/2;
			if(i<=mid) tree[curr] = get_minimum_update(tree[curr],recur_update(l,mid,i,v,left_child(curr)));
			else tree[curr] = get_minimum_update(tree[curr],recur_update(mid+1,r,i,v,right_child(curr)));
			return tree[curr];
		}
		pvi recur_lookup(int l,int r,int a,int b,int curr){
			if(l==a&&r==b){
				return tree[curr];
			}
			if(a<l||b>r){
				ll* blank = new ll[80]; for(int i=0;i<80;i++) blank[i]=0LL;
				return mp(blank,INT_MAX);
			}
			int mid = l+(r-l)/2;
			if(a>=l&&b<=mid) return recur_lookup(l,mid,a,b,left_child(curr));
			if(a>mid&&b<=r) return recur_lookup(mid+1,r,a,b,right_child(curr));
			return get_minimum_lookup(recur_lookup(l,mid,a,b,left_child(curr)),recur_lookup(mid+1,r,a,b,right_child(curr)));
		}
		void update(int i,int v){
			tree[0] = recur_update(0,n-1,i,v,0);
		}
		pvi lookup(int a,int b){
			return recur_lookup(0,n-1,a,b,0);
		}
};
ll divide(int l,int r,ST* seg,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	auto mm = seg->lookup(l,r);
	//int ori_n = mm.first.size();
	int ori_n=0;
	for(int i=0;i<ncap;i++){
		int x = mm.first[i];
		while(x>0){
			x-=x&(-x); ori_n++;
		}
	}
	ll tot=0; int start=l-1;
	int end=0;
	for(int i=0;i<ncap;i++){
		ll x = mm.first[i];
		while(x>0){
			ll pos = x&(-x);
			end = (i*64) + (int)log2(pos);
			tot += divide(start+1,end-1,seg,ncap);
			start = end;
			x -= pos;
		}
	}
	if(start < r){
		tot += divide(start+1,r,seg,ncap);
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n,x;
	cin>>n;
	ST seg(n);
	for(int i=0;i<n;i++){
		cin>>x; seg.update(i,x);
	}
	int res = divide(0,n-1,&seg,(int)ceil((double)n/64));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
ll divide(int l,int r,int neg){
	if(l>r) return 0LL; if(l==r)return 1LL;
	int ori_n=0;
	////
	ll tot=0; int start=l-1; int end=0;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini){
		tot += divide(start+1,i-1,neg);
		start = i;
		ori_n++;
	}
	////
	if(start < r){
		tot += divide(start+1,r,neg);
	}
	return min(mini-neg+tot,(ll)(r-l+1));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,0);
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
ll divide(int l,int r,int neg){
	if(l>r) return 0LL; if(l==r)return 1LL;
	int ori_n=0;
	////
	ll tot=0; int start=l-1; int end=0;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini){
		tot += divide(start+1,i-1,neg+mini);
		start = i;
		ori_n++;
	}
	////
	if(start < r){
		tot += divide(start+1,r,neg+mini);
	}
	return min(mini-neg+tot,(ll)((mini-neg==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,0);
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
int divide(int l,int r,int neg){
	if(l>r) return 0; if(l==r)return arr[l]==0?0:1;
	////
	int tot=0; int start=l-1;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini){
		tot += divide(start+1,i-1,mini);
		start = i;
	}
	////
	if(start < r){
		tot += divide(start+1,r,mini);
	}
	return min(mini-neg+tot,(r-l+1));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,0);
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
ll divide(int l,int r,int neg){
	if(l>r) return 0LL; if(l==r)return l==0?0LL:1LL;
	int ori_n=0;
	////
	ll tot=0; int start=l-1;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini){
		tot += divide(start+1,i-1,neg);
		start = i;
		ori_n++;
	}
	////
	if(start < r){
		tot += divide(start+1,r,neg);
	}
	return min(mini-neg+tot,(ll)(r-l+1));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,0);
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
int divide(int l,int r,int neg){
	if(l>r) return 0; if(l==r)return arr[l]==0?0:1;
	////
	int tot=0; int start=l-1;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini){
		tot += divide(start+1,i-1,neg);
		start = i;
	}
	////
	if(start < r){
		tot += divide(start+1,r,neg);
	}
	return min(mini-neg+tot,(r-l+1));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,0);
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
ll divide(int l,int r,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	int ori_n=0;
	////
	ll tot=0; int start=l-1; int end=0;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini){
		tot += divide(start+1,i-1,ncap);
		start = i;
		ori_n++;
	}
	////
	if(start < r){
		tot += divide(start+1,r,ncap);
	}
	return min(mini+tot,(ll)((mini==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,(int)(ceil((double)n/64)));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
ll divide(int l,int r,int neg){
	if(l>r) return 0LL; if(l==r)return 1LL;
	int ori_n=0;
	////
	ll tot=0; int start=l-1; int end=0;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini){
		tot += divide(start+1,i-1,neg);
		start = i;
		ori_n++;
	}
	////
	if(start < r){
		tot += divide(start+1,r,neg);
	}
	return min(mini-neg+tot,(ll)(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,0);
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
int divide(int l,int r,int neg){
	if(l>r) return 0; if(l==r)return arr[l]==0?0:1;
	bool occ=false;
	int tot=0; int start=l-1;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++){
		if(arr[i]!=mini && !occ){start=i;occ=true;continue;}
		if(arr[i]==mini && occ){
			tot += divide(start,i-1,neg);
			occ=false;
		}
	}
	////
	if(occ){
		tot += divide(start,r,neg);
	}
	return min(mini-neg+tot,(r-l+1));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,0);
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
//typedef pair<set<int>,int> pvi;
typedef long long ll;
typedef pair<ll*,int> pvi;

int arr[5001];
class ST{
	public:
		int icap;
		int n;
		int height;
		pvi* tree;
		int left_child(int i){return i*2+1;}
		int right_child(int i){return i*2+2;}
		pvi get_minimum_update(pvi current,pvi other){
			if(current.second==other.second){
    			//current.first.insert(other.first.begin(), other.first.end());
    			for(int i=0;i<icap;i++) current.first[i] = current.first[i]|other.first[i];
    			if(other.second==INT_MAX) delete other.first;
				return current;
			}
			if(current.second>other.second){
				if(current.second==INT_MAX) delete current.first;
				return other;
			}
			if(other.second==INT_MAX) delete other.first;
			return current;
		}
		pvi get_minimum_lookup(pvi current,pvi other){
			if(current.second==other.second){
    			//current.first.insert(other.first.begin(), other.first.end());
    			for(int i=0;i<icap;i++) current.first[i] = current.first[i]|other.first[i];
				return current;
			}
			if(current.second>other.second){
				return other;
			}
			return current;
		}
		ST(int _n){
			n = _n; icap = (int)ceil((double)n/64);
			height = (int)(ceil(log2(n)));
			tree = new pvi[2*(1<<height)-1];
			//for(int i=0;i<(2*(1<<height)-1);i++) tree[i]=mp(set<int>(),INT_MAX);
			for(int i=0;i<(2*(1<<height)-1);i++){
				ll* _bits = new ll[icap+1]; for(int j=0;j<icap;j++) _bits[j]=0LL;
				tree[i]=mp(_bits,INT_MAX);
			}
		}
		pvi recur_update(int l,int r,int i,int v,int curr){
			if(l==r){
//				set<int> vp; vp.insert(i);
//				tree[curr] = mp(vp,v);
				tree[curr].first[i/64] = tree[curr].first[i/64] | (1LL<<(i%64));
				tree[curr].second = v;
				return tree[curr];
			}
			int mid = l+(r-l)/2;
			if(i<=mid) tree[curr] = get_minimum_update(tree[curr],recur_update(l,mid,i,v,left_child(curr)));
			else tree[curr] = get_minimum_update(tree[curr],recur_update(mid+1,r,i,v,right_child(curr)));
			return tree[curr];
		}
		pvi recur_lookup(int l,int r,int a,int b,int curr){
			if(l==a&&r==b){
				return tree[curr];
			}
			if(a<l||b>r){
				ll* blank = new ll[80]; for(int i=0;i<80;i++) blank[i]=0LL;
				return mp(blank,INT_MAX);
			}
			int mid = l+(r-l)/2;
			if(a>=l&&b<=mid) return recur_lookup(l,mid,a,b,left_child(curr));
			if(a>mid&&b<=r) return recur_lookup(mid+1,r,a,b,right_child(curr));
			return get_minimum_lookup(recur_lookup(l,mid,a,b,left_child(curr)),recur_lookup(mid+1,r,a,b,right_child(curr)));
		}
		void update(int i,int v){
			tree[0] = recur_update(0,n-1,i,v,0);
		}
		pvi lookup(int a,int b){
			return recur_lookup(0,n-1,a,b,0);
		}
};
ll divide(int l,int r,ST* seg,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	auto mm = seg->lookup(l,r);
	//int ori_n = mm.first.size();
	int ori_n=0;
	for(int i=0;i<ncap;i++){
		int x = mm.first[i];
		while(x>0){
			x-=x&(-x); ori_n++;
		}
	}
	ll tot=0; int start=l-1;
	int end=0;
	for(int i=0;i<ncap;i++){
		ll x = mm.first[i];
		while(x>0){
			ll pos = x&(-x);
			end = (i*64) + (int)log2(pos);
			tot += divide(start+1,end-1,seg,ncap);
			start = end;
			x -= pos;
		}
	}
	if(start < r){
		tot += divide(start+1,r,seg,ncap);
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	ST seg(n);
	for(int i=0;i<n;i++){
		cin>>arr[i]; seg.update(i,arr[i]);
	}
	int res = divide(0,n-1,&seg,(int)ceil((double)n/64));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
pvi lookup(int l,int r){
	int mini = INT_MAX; ll* bits = new ll[80]; for(int i=0;i<80;i++) bits[i]=0LL;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini) {
		bits[i/64] = bits[i/64] | (1LL<<(i%64));
	}
	return mp(bits,mini);
}
ll divide(int l,int r,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	auto mm = lookup(l,r);
	int ori_n=0;
	for(int i=0;i<ncap;i++){
		int x = mm.first[i];
		while(x>0){
			x-=x&(-x); ori_n++;
		}
	}
	ll tot=0; int start=l-1;
	int end=0;
	for(int i=0;i<ncap;i++){
		ll x = mm.first[i];
		while(x>0){
			ll pos = x&(-x);
			end = (i*64) + (int)log2(pos);
			tot += divide(start+1,end-1,ncap);
			start = end;
			x -= pos;
		}
	}
	if(start < r){
		tot += divide(start+1,r,ncap);
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,(int)(ceil((double)n/64)));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
//typedef pair<set<int>,int> pvi;
typedef long long ll;
typedef pair<ll*,int> pvi;

class ST{
	public:
		int icap;
		int n;
		int height;
		pvi* tree;
		int left_child(int i){return i*2+1;}
		int right_child(int i){return i*2+2;}
		pvi get_minimum(pvi current,pvi other){
			if(current.second==other.second){
    			//current.first.insert(other.first.begin(), other.first.end());
    			for(int i=0;i<icap;i++) current.first[i] = current.first[i]|other.first[i];
				return current;
			}
			if(current.second>other.second){
				return other;
			}
			return current;
		}
		ST(int _n){
			n = _n; icap = (int)ceil((double)n/64);
			height = (int)(ceil(log2(n)));
			tree = new pvi[2*(1<<height)-1];
			//for(int i=0;i<(2*(1<<height)-1);i++) tree[i]=mp(set<int>(),INT   _MAX);
			for(int i=0;i<(2*(1<<height)-1);i++){
				ll* _bits = new ll[icap+1]; for(int j=0;j<icap;j++) _bits[j]=0LL;
				tree[i]=mp(_bits,INT_MAX);
			}
		}
		pvi recur_update(int l,int r,int i,int v,int curr){
			if(l==r){
				tree[curr].first[i/64] = tree[curr].first[i/64] | (1LL<<(i%64));
				tree[curr].second = v;
				return tree[curr];
			}
			int mid = l+(r-l)/2;
			if(i<=mid) tree[curr] = get_minimum(tree[curr],recur_update(l,mid,i,v,left_child(curr)));
			else tree[curr] = get_minimum(tree[curr],recur_update(mid+1,r,i,v,right_child(curr)));
			return tree[curr];
		}
		pvi recur_lookup(int l,int r,int a,int b,int curr){
			if(l==a&&r==b){
				return tree[curr];
			}
			if(a<l||b>r){
				ll* blank = new ll[80]; for(int i=0;i<80;i++) blank[i]=0LL;
				return mp(blank,INT_MAX);
			}
			int mid = l+(r-l)/2;
			if(a>=l&&b<=mid) return recur_lookup(l,mid,a,b,left_child(curr));
			if(a>mid&&b<=r) return recur_lookup(mid+1,r,a,b,right_child(curr));
			return get_minimum(recur_lookup(l,mid,a,b,left_child(curr)),recur_lookup(mid+1,r,a,b,right_child(curr)));
		}
		void update(int i,int v){
			tree[0] = recur_update(0,n-1,i,v,0);
		}
		pvi lookup(int a,int b){
			return recur_lookup(0,n-1,a,b,0);
		}
};
ST* seg;
ll divide(int l,int r,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	auto mm = seg->lookup(l,r);
	//int ori_n = mm.first.size();
	int ori_n=0;
	for(int i=0;i<ncap;i++){
		int x = mm.first[i];
		while(x>0){
			x-=x&(-x); ori_n++;
		}
	}
	ll tot=0; int start=l-1;
	int end=0;
	for(int i=0;i<ncap;i++){
		ll x = mm.first[i];
		while(x>0){
			ll pos = x&(-x);
			end = (i*64) + (int)log2(pos);
			tot += divide(start+1,end-1,ncap);
			start = end;
			x -= pos;
		}
	}
	if(start < r){
		tot += divide(start+1,r,ncap);
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n,x;
	cin>>n;
	seg = new ST(n);
	for(int i=0;i<n;i++){
		cin>>x; seg->update(i,x);
	}
	int res = divide(0,n-1,(int)ceil((double)n/64));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
//typedef pair<set<int>,int> pvi;
typedef long long ll;
typedef pair<ll*,int> pvi;

int arr[5001];
class ST{
	public:
		int icap;
		int n;
		int height;
		pvi* tree;
		int left_child(int i){return i*2+1;}
		int right_child(int i){return i*2+2;}
		pvi get_minimum(pvi current,pvi other){
			if(current.second==INT_MAX&&other.second==INT_MAX) return current;
			if(current.second==other.second){
    			//current.first.insert(other.first.begin(), other.first.end());
    			for(int i=0;i<icap;i++) current.first[i] = current.first[i]|other.first[i];
				return current;
			}
			if(current.second>other.second){
				return other;
			}
			return current;
		}
		ST(int _n){
			n = _n; icap = (int)ceil((double)n/64);
			height = (int)(ceil(log2(n)));
			tree = new pvi[2*(1<<height)-1];
			//for(int i=0;i<(2*(1<<height)-1);i++) tree[i]=mp(set<int>(),INT_MAX);
			for(int i=0;i<(2*(1<<height)-1);i++){
				ll* _bits = new ll[icap+1]; for(int j=0;j<icap;j++) _bits[j]=0LL;
				tree[i]=mp(_bits,INT_MAX);
			}
		}
		pvi recur_update(int l,int r,int i,int v,int curr){
			if(l==r){
//				set<int> vp; vp.insert(i);
//				tree[curr] = mp(vp,v);
				tree[curr].first[i/64] = tree[curr].first[i/64] | (1LL<<(i%64));
				tree[curr].second = v;
				return tree[curr];
			}
			int mid = l+(r-l)/2;
			if(i<=mid) tree[curr] = get_minimum(tree[curr],recur_update(l,mid,i,v,left_child(curr)));
			else tree[curr] = get_minimum(tree[curr],recur_update(mid+1,r,i,v,right_child(curr)));
			return tree[curr];
		}
		pvi recur_lookup(int l,int r,int a,int b,int curr){
			if(l==a&&r==b){
				return tree[curr];
			}
			if(a<l||b>r){
				ll* blank = new ll[1];
				return mp(blank,INT_MAX);
			}
			int mid = l+(r-l)/2;
			if(a>=l&&b<=mid) return recur_lookup(l,mid,a,b,left_child(curr));
			if(a>mid&&b<=r) return recur_lookup(mid+1,r,a,b,right_child(curr));
			return get_minimum(recur_lookup(l,mid,a,b,left_child(curr)),recur_lookup(mid+1,r,a,b,right_child(curr)));
		}
		void update(int i,int v){
			tree[0] = recur_update(0,n-1,i,v,0);
		}
		pvi lookup(int a,int b){
			return recur_lookup(0,n-1,a,b,0);
		}
};
ll divide(int l,int r,ST* seg,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	auto mm = seg->lookup(l,r);
	//int ori_n = mm.first.size();
	int ori_n=0;
	for(int i=0;i<ncap;i++){
		int x = mm.first[i];
		while(x>0){
			x-=x&(-x); ori_n++;
		}
	}
	ll tot=0; int start=l-1;
	int end=0;
	for(int i=0;i<ncap;i++){
		ll x = mm.first[i];
		while(x>0){
			ll pos = x&(-x);
			end = (i*64) + (int)log2(pos);
			tot += divide(start+1,end-1,seg,ncap);
			start = end;
			x -= pos;
		}
	}
	if(start < r){
		tot += divide(start+1,r,seg,ncap);
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	ST seg(n);
	for(int i=0;i<n;i++){
		cin>>arr[i]; seg.update(i,arr[i]);
	}
	int res = divide(0,n-1,&seg,(int)ceil((double)n/64));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
int divide(int l,int r,int neg){
	if(l>r) return 0; if(l==r)return arr[l]==0?0:1;
	bool occ=false;
	int tot=0; int start=l-1;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++){
		if(arr[i]!=mini && !occ){start=i;occ=true;continue;}
		if(arr[i]==mini){
			tot += divide(start,i-1,neg);
			occ=false;
		}
	}
	////
	if(occ){
		tot += divide(start,r,neg);
	}
	return min(mini-neg+tot,(r-l+1));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,0);
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
pvi lookup(int l,int r,int& ori_n){
	int mini = INT_MAX; ll* bits = new ll[80]; for(int i=0;i<80;i++) bits[i]=0LL;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini) {
		bits[i/64] = bits[i/64] | (1LL<<(i%64)); ori_n++;
	}
	return mp(bits,mini);
}
ll divide(int l,int r,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	int ori_n=0;
	auto mm = lookup(l,r,ori_n);
	ll tot=0; int start=l-1;
	int end=0;
	for(int i=0;i<ncap;i++){
		ll x = mm.first[i];
		while(x>0){
			ll pos = x&(-x);
			end = (i*64) + (int)log2(pos);
			tot += divide(start+1,end-1,ncap);
			start = end;
			x -= pos;
		}
	}
	if(start < r){
		tot += divide(start+1,r,ncap);
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,(int)(ceil((double)n/64)));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef long long ll;
typedef pair<ll*,int> pvi;
int arr[5001];
ll divide(int l,int r,int neg){
	if(l>r) return 0LL; if(l==r)return 1LL;
	int ori_n=0;
	////
	ll tot=0; int start=l-1; int end=0;
	int mini = INT_MAX;
	for(int i=l;i<=r;i++) mini = min(arr[i],mini);
	for(int i=l;i<=r;i++) if(arr[i]==mini){
		tot += divide(start+1,i-1,neg);
		start = i;
		ori_n++;
	}
	////
	if(start < r){
		tot += divide(start+1,r,neg);
	}
	return min(mini-neg+tot,(ll)((mini-neg==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int res = divide(0,n-1,0);
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
//typedef pair<set<int>,int> pvi;
typedef long long ll;
typedef pair<ll*,int> pvi;

int arr[5001];
class ST{
	public:
		int icap;
		int n;
		int height;
		pvi* tree;
		int left_child(int i){return i*2+1;}
		int right_child(int i){return i*2+2;}
		pvi get_minimum(pvi current,pvi other){
			if(current.second==other.second){
    			//current.first.insert(other.first.begin(), other.first.end());
    			for(int i=0;i<icap;i++) current.first[i] = current.first[i]|other.first[i];
				return current;
			}
			if(current.second>other.second){
				return other;
			}
			return current;
		}
		ST(int _n){
			n = _n; icap = (int)ceil((double)n/64);
			height = (int)(ceil(log2(n)));
			tree = new pvi[2*(1<<height)-1];
			//for(int i=0;i<(2*(1<<height)-1);i++) tree[i]=mp(set<int>(),INT_MAX);
			for(int i=0;i<(2*(1<<height)-1);i++){
				ll* _bits = new ll[icap+1]; for(int j=0;j<icap;j++) _bits[j]=0LL;
				tree[i]=mp(_bits,INT_MAX);
			}
		}
		pvi recur_update(int l,int r,int i,int v,int curr){
			if(l==r){
//				set<int> vp; vp.insert(i);
//				tree[curr] = mp(vp,v);
				tree[curr].first[i/64] = tree[curr].first[i/64] | (1LL<<(i%64));
				tree[curr].second = v;
				return tree[curr];
			}
			int mid = l+(r-l)/2;
			if(i<=mid) tree[curr] = get_minimum(tree[curr],recur_update(l,mid,i,v,left_child(curr)));
			else tree[curr] = get_minimum(tree[curr],recur_update(mid+1,r,i,v,right_child(curr)));
			return tree[curr];
		}
		pvi recur_lookup(int l,int r,int a,int b,int curr){
			if(l==a&&r==b){
				return tree[curr];
			}
			if(a<l||b>r) return mp(new ll[1],INT_MAX);
			int mid = l+(r-l)/2;
			if(a>=l&&b<=mid) return recur_lookup(l,mid,a,b,left_child(curr));
			if(a>mid&&b<=r) return recur_lookup(mid+1,r,a,b,right_child(curr));
			return get_minimum(recur_lookup(l,mid,a,b,left_child(curr)),recur_lookup(mid+1,r,a,b,right_child(curr)));
		}
		void update(int i,int v){
			tree[0] = recur_update(0,n-1,i,v,0);
		}
		pvi lookup(int a,int b){
			return recur_lookup(0,n-1,a,b,0);
		}
};
ll divide(int l,int r,ST* seg,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	auto mm = seg->lookup(l,r);
	//int ori_n = mm.first.size();
	int ori_n=0;
	for(int i=0;i<ncap;i++){
		int x = mm.first[i];
		while(x>0){
			x-=x&(-x); ori_n++;
		}
	}
	ll tot=0; int start=l-1;
	int end=0;
	for(int i=0;i<ncap;i++){
		ll x = mm.first[i];
		while(x>0){
			ll pos = x&(-x);
			end = (i*64) + (int)log2(pos);
			tot += divide(start+1,end-1,seg,ncap);
			start = end;
			x -= pos;
		}
	}
	if(start < r){
		tot += divide(start+1,r,seg,ncap);
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	ST seg(n);
	for(int i=0;i<n;i++){
		cin>>arr[i]; seg.update(i,arr[i]);
	}
	int res = divide(0,n-1,&seg,(int)ceil((double)n/64));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
//typedef pair<set<int>,int> pvi;
typedef long long ll;
typedef pair<ll*,int> pvi;

int arr[5001];
class ST{
	public:
		int icap;
		int n;
		int height;
		pvi* tree;
		int left_child(int i){return i*2+1;}
		int right_child(int i){return i*2+2;}
		pvi get_minimum(pvi current,pvi other){
			if(current.second==other.second){
    			//current.first.insert(other.first.begin(), other.first.end());
    			for(int i=0;i<icap;i++) current.first[i] = current.first[i]|other.first[i];
				return current;
			}
			if(current.second>other.second){
				return other;
			}
			return current;
		}
		ST(int _n){
			n = _n; icap = (int)ceil((double)n/64);
			height = (int)(ceil(log2(n)));
			tree = new pvi[2*(1<<height)-1];
			//for(int i=0;i<(2*(1<<height)-1);i++) tree[i]=mp(set<int>(),INT_MAX);
			for(int i=0;i<(2*(1<<height)-1);i++){
				ll* _bits = new ll[icap+1]; for(int j=0;j<icap;j++) _bits[j]=0LL;
				tree[i]=mp(_bits,INT_MAX);
			}
		}
		pvi recur_update(int l,int r,int i,int v,int curr){
			if(l==r){
//				set<int> vp; vp.insert(i);
//				tree[curr] = mp(vp,v);
				tree[curr].first[i/64] = tree[curr].first[i/64] | (1LL<<(i%64));
				tree[curr].second = v;
				return tree[curr];
			}
			int mid = l+(r-l)/2;
			if(i<=mid) tree[curr] = get_minimum(tree[curr],recur_update(l,mid,i,v,left_child(curr)));
			else tree[curr] = get_minimum(tree[curr],recur_update(mid+1,r,i,v,right_child(curr)));
			return tree[curr];
		}
		pvi recur_lookup(int l,int r,int a,int b,int curr){
			if(l==a&&r==b){
				return tree[curr];
			}
			if(a<l||b>r){
				ll* blank = new ll[80]; for(int i=0;i<80;i++) blank[i]=0LL;
				return mp(blank,INT_MAX);
			}
			int mid = l+(r-l)/2;
			if(a>=l&&b<=mid) return recur_lookup(l,mid,a,b,left_child(curr));
			if(a>mid&&b<=r) return recur_lookup(mid+1,r,a,b,right_child(curr));
			return get_minimum(recur_lookup(l,mid,a,b,left_child(curr)),recur_lookup(mid+1,r,a,b,right_child(curr)));
		}
		void update(int i,int v){
			tree[0] = recur_update(0,n-1,i,v,0);
		}
		pvi lookup(int a,int b){
			return recur_lookup(0,n-1,a,b,0);
		}
};
ll divide(int l,int r,ST* seg,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	auto mm = seg->lookup(l,r);
	//int ori_n = mm.first.size();
	int ori_n=0;
	for(int i=0;i<ncap;i++){
		int x = mm.first[i];
		while(x>0){
			x-=x&(-x); ori_n++;
		}
	}
	ll tot=0; int start=l-1;
	int end=0;
	for(int i=0;i<ncap;i++){
		ll x = mm.first[i];
		while(x>0){
			ll pos = x&(-x);
			end = (i*64) + (int)log2(pos);
			tot += divide(start+1,end-1,seg,ncap);
			start = end;
			x -= pos;
		}
	}
	if(start < r){
		tot += divide(start+1,r,seg,ncap);
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	ST seg(n);
	for(int i=0;i<n;i++){
		cin>>arr[i]; seg.update(i,arr[i]);
	}
	int res = divide(0,n-1,&seg,(int)ceil((double)n/64));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
//typedef pair<set<int>,int> pvi;
typedef long long ll;
typedef pair<ll*,int> pvi;

int arr[5001];
class ST{
	public:
		int icap;
		int n;
		int height;
		pvi* tree;
		int left_child(int i){return i*2+1;}
		int right_child(int i){return i*2+2;}
		pvi get_minimum(pvi current,pvi other){
			if(current.second==other.second){
    			//current.first.insert(other.first.begin(), other.first.end());
    			for(int i=0;i<icap;i++) current.first[i] = current.first[i]|other.first[i];
				return current;
			}
			if(current.second>other.second){
				return other;
			}
			return current;
		}
		ST(int _n){
			n = _n; icap = (int)ceil((double)n/64);
			height = (int)(ceil(log2(n)));
			tree = new pvi[2*(1<<height)-1];
			//for(int i=0;i<(2*(1<<height)-1);i++) tree[i]=mp(set<int>(),INT_MAX);
			for(int i=0;i<(2*(1<<height)-1);i++){
				ll* _bits = new ll[icap+1]; for(int j=0;j<icap;j++) _bits[j]=0LL;
				tree[i]=mp(_bits,INT_MAX);
			}
		}
		pvi recur_update(int l,int r,int i,int v,int curr){
			if(l==r){
//				set<int> vp; vp.insert(i);
//				tree[curr] = mp(vp,v);
				tree[curr].first[i/64] = tree[curr].first[i/64] | (1LL<<(i%64));
				tree[curr].second = v;
				return tree[curr];
			}
			int mid = l+(r-l)/2;
			if(i<=mid) tree[curr] = get_minimum(tree[curr],recur_update(l,mid,i,v,left_child(curr)));
			else tree[curr] = get_minimum(tree[curr],recur_update(mid+1,r,i,v,right_child(curr)));
			return tree[curr];
		}
		pvi recur_lookup(int l,int r,int a,int b,int curr){
			if(l==a&&r==b){
				return tree[curr];
			}
			if(a<l||b>r) return mp(new ll[1],INT_MAX);
			int mid = l+(r-l)/2;
			if(a>=l&&b<=mid) return recur_lookup(l,mid,a,b,left_child(curr));
			if(a>mid&&b<=r) return recur_lookup(mid+1,r,a,b,right_child(curr));
			return get_minimum(recur_lookup(l,mid,a,b,left_child(curr)),recur_lookup(mid+1,r,a,b,right_child(curr)));
		}
		void update(int i,int v){
			tree[0] = recur_update(0,n-1,i,v,0);
		}
		pvi lookup(int a,int b){
			return recur_lookup(0,n-1,a,b,0);
		}
};
ll divide(int l,int r,ST* seg,int ncap){
	if(l>r) return 0LL; if(l==r)return 1LL;
	auto mm = seg->lookup(l,r);
	//int ori_n = mm.first.size();
	int ori_n=0;
	for(int i=0;i<ncap;i++){
		int x = mm.first[i];
		while(x>0){
			x-=x&(-x); ori_n++;
		}
	}
	//mm.first.insert(r+1);
	mm.first[(r+1)/64] = mm.first[(r+1)/64] | (1LL<<((r+1)%64));
	ll tot=0; int start=l-1;
	int end=0;
	for(int i=0;i<ncap;i++){
		ll x = mm.first[i];
		while(x>0){
			ll pos = x&(-x);
			end = (i*64) + (int)log2(pos);
			tot += divide(start+1,end-1,seg,ncap);
			start = end;
			x -= pos;
		}
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	ST seg(n);
	for(int i=0;i<n;i++){
		cin>>arr[i]; seg.update(i,arr[i]);
	}
	int res = divide(0,n-1,&seg,(int)ceil((double)n/64));
	cout<<res<<endl;
}


#include<bits/stdc++.h>
//TRIPLE
template<typename A,typename B,typename C>
struct triple{
	A first;B second;C third;
};
template<typename A,typename B,typename C>
triple<A,B,C> make_triple(A a,B b,C c){
	triple<A,B,C> _;
	_.first=a;_.second=b;_.third=c;
	return _;
}
////////
#define mp make_pair
#define mt make_triple
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef triple<int,int,int> tiii;
typedef pair<set<int>,int> pvi;
typedef long long ll;

int arr[5001];
class ST{
	public:
		int n;
		int height;
		pvi* tree;
		int left_child(int i){return i*2+1;}
		int right_child(int i){return i*2+2;}
		pvi get_minimum(pvi current,pvi other){
			if(current.second==other.second){
    			current.first.insert(other.first.begin(), other.first.end());
				return current;
			}
			if(current.second>other.second){
				return other;
			}
			return current;
		}
		ST(int _n){
			n = _n;
			height = (int)(ceil(log2(n)));
			tree = new pvi[2*(1<<height)-1];
			for(int i=0;i<(2*(1<<height)-1);i++) tree[i]=mp(set<int>(),INT_MAX);
		}
		pvi recur_update(int l,int r,int i,int v,int curr){
			if(l==r){
				set<int> vp; vp.insert(i);
				tree[curr] = mp(vp,v);
				return tree[curr];
			}
			int mid = l+(r-l)/2;
			if(i<=mid) tree[curr] = get_minimum(tree[curr],recur_update(l,mid,i,v,left_child(curr)));
			else tree[curr] = get_minimum(tree[curr],recur_update(mid+1,r,i,v,right_child(curr)));
			return tree[curr];
		}
		pvi recur_lookup(int l,int r,int a,int b,int curr){
			if(l==a&&r==b){
				return tree[curr];
			}
			if(a<l||b>r) return mp(set<int>(),INT_MAX);
			int mid = l+(r-l)/2;
			if(a>=l&&b<=mid) return recur_lookup(l,mid,a,b,left_child(curr));
			if(a>mid&&b<=r) return recur_lookup(mid+1,r,a,b,right_child(curr));
			return get_minimum(recur_lookup(l,mid,a,b,left_child(curr)),recur_lookup(mid+1,r,a,b,right_child(curr)));
		}
		void update(int i,int v){
			tree[0] = recur_update(0,n-1,i,v,0);
		}
		pvi lookup(int a,int b){
			return recur_lookup(0,n-1,a,b,0);
		}
};
ll divide(int l,int r,ST* seg){
	if(l>r) return 0LL; if(l==r)return 1LL;
	auto mm = seg->lookup(l,r);
	int ori_n = mm.first.size();
	mm.first.insert(r+1);
	ll tot=0; int start=l-1;
	for(int end:mm.first){
		tot += divide(start+1,end-1,seg);
		start = end;
	}
	return min(mm.second+tot,(ll)((mm.second==0)?((r-l+1)-ori_n):(r-l+1)));
}
int main(){
	int n;
	cin>>n;
	ST seg(n);
	for(int i=0;i<n;i++){
		cin>>arr[i]; seg.update(i,arr[i]);
	}
	int res = divide(0,n-1,&seg);
	cout<<res<<endl;
}


#include<iostream>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<climits>
using namespace std ;
#include <unordered_map>
typedef long long ll ;
 #include<climits>
 #include<algorithm>
 const int M=1e9+7;
 /*
int solve(int arr[] ,int n , int l,int**output){

    if(n==0){
        if(l==1){
            return 1 ;
        }
        return 0 ;
    }
    if(output[n][l] != -1){
        return output[n][l] ;

    }
    int a = solve(arr+1,n-1,0,output) +1;
    int b = solve(arr+1,n-1,1,output) +1 ;

    if(arr[0] ==1){
        b--;
    }
    if(l == 1){
        a++ ;
    }
    if(arr[0] == 0){

        a-- ;
        output[n][l] = a ;
        return a ;
    }
    output[n][l] = min(a,b) ;
    return min(a,b) ;

}*/
int solve1(int s, int e , int *arr,int n,int k ){

    if(s>=e){
      if(k){

          if(arr[e] <= 1){
              return 0 ;
          }
          else{

              return 1 ;
          }
      }
      else{
          if(arr[s] <= 1){
              return 0 ;
          }
          else{

              return 1 ;
          }

      }
    }

    int m = INT_MAX ;
    int mi = 0 ;
    for(int i = s ; i <= e ; i++){
        if(m > arr[i]){
            m = arr[i] ;
            mi = i ;
        }

    }
    int l = arr[mi] -1;

    for(int i = s ; i <= e ;i++){

        arr[i]= arr[i] - (l) ;

    }

    int a = 0 ;
    int b = 0 ;

    a = solve1(s,mi-1,arr,n,0) ;
    b = solve1(mi+1,e,arr,n,1) ;

    return a +b + l  ;

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     int n ;
     cin >> n ;
     int *arr = new int[n] ;
     for(int i =0 ; i < n ; i++ ){

         cin >> arr[i] ;

     }
     /*int**output = new int*[n+1] ;
     for(int i = 0 ; i <= n ; i++){
         output[i] = new int[2] ;
         output[i][0] = -1;
         output[i][1] = -1 ;

     }
     int k = solve(arr,n,0,output) ;
     cout << k ;*/
   int s= 0 ;
   int count = 0 ;
   for(int  i = 0 ; i < n ; i++){
       if(i == n -1){
           int l = solve1(s,n-1,arr,n,0)+1 ;
           if(arr[i] == 0 && s >= n-1){
               l-- ;
           }
           count+= l ;
       }

       if(arr[i] < 1){
           int l = solve1(s,i-1,arr,n,0) +1 ;

           count+=l ;
           s = i+1 ;
           if(s > i-1){
               count-- ;
           }
       }

   }
   cout << count ;

}