#include using namespace std; int main(){ int n,m,p,c; while(scanf("%d%d%d%d",&n,&m,&p,&c)==4&&n){ printf("%d\n",n+c-(m+c-p)); } return 0; }