long s,a=2e9,b;i; main(C,D){ for(scanf("%*d");~scanf("%d%d",&C,&D);s+=C+D)a=fmin(a,b-D),b=fmin(i++?b:a+C,a+C); printf("%d",s+b); }