import java.util.Scanner; import java.util.HashSet; import java.awt.Point; class Main{ private static final int[] dx = {1,-1,0,0}; private static final int[] dy = {0,0,1,-1}; public static void main(String[] args){ Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); int Si = sc.nextInt(); int Sj = sc.nextInt(); int Gi = sc.nextInt(); int Gj = sc.nextInt(); int ans = dfs(Si,Sj,Gi,Gj,H,W,new HashSet<>()); System.out.println(ans); } private static int dfs(int x,int y,int gx,int gy,int H,int W,HashSet set){ int count = 0; for(int i=0;i<4;i++){ int nx = x+dx[i]; int ny = y+dy[i]; if(set.contains(new Point(nx,ny))) count++; } if(count>1) return 0; if(x==gx&&y==gy) return 1; Point p = new Point(x,y); set.add(p); int ans = 0; for(int i=0;i<4;i++){ int nx = x+dx[i]; int ny = y+dy[i]; if(0