var
a,b,c,n:shortint;
jk,sk:array[1..3] of shortint;
ans:qword;
begin
assign(input,'combo.in');
assign(output,'combo.out');
reset(input);
rewrite(output);
//while not(eof) do
//begin
readln(n);
for a:=1 to 3 do
read(jk[a]);
for a:=1 to 3 do
read(sk[a]);
ans:=0;
for a:=1 to n do
for b:=1 to n do
for c:=1 to n do
if ((abs(a-jk[1])<3) or (abs(a-jk[1])>n-3)) and ((abs(b-jk[2])<3) or (abs(b-jk[2])>n-3)) and ((abs(c-jk[3])<3) or (abs(c-jk[3])>n-3)) or (((abs(a-sk[1])<3) or (abs(a-sk[1])>n-3)) and ((abs(b-sk[2])<3) or (abs(b-sk[2])>n-3)) and ((abs(c-sk[3])<3) or
(abs(c-sk[3])>n-3))) then
//begin
inc(ans);
//readln;
//end;
writeln(ans);
//end;
close(input);
close(output);
end.