import java.io.*;
import java.util.*;

public class chocolate_av implements Runnable {
	public static void main(String[] args) {
		new Thread(new chocolate_av()).start();
	}

	BufferedReader br;

	StringTokenizer in;

	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}

		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public void solve() throws IOException {
		int m = nextInt();
		int n = nextInt();
		
		int[] color = new int[n * m];
		
		int[][] a = new int[n + 1][m + 1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				a[i][j] = nextInt();
				color[a[i][j] - 1]++;
				if (color[a[i][j] - 1] > 2)
					throw new AssertionError("2 same colors!!!");
			}
		}
		
		boolean[][] good = new boolean[n][m];		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (good[i][j] == true)
					continue;
				
				if (a[i][j + 1] == a[i][j]){
					good[i][j + 1] = true;
					continue;
				}
				
				if (a[i + 1][j] == a[i][j]){
					good[i + 1][j] = true;
					continue;
				}
				
				throw new AssertionError("We haven't connectivity!!!");
			}
		}
		
		up: for (int i = 0; i < n - 1; i++) {
			for (int j = 0; j < m; j++) {
				if (a[i][j] == a[i + 1][j])
					continue up;
			}
			
			out.println("Yes");
			return;
		}
		
		up: for (int j = 0; j < m - 1; j++) {
			for (int i = 0; i < n; i++) {
				if (a[i][j] == a[i][j + 1])
					continue up;
			}
			
			out.println("Yes");
			return;
		}
		
		out.println("No");
	}

	public void run() {
		try {
			br = new BufferedReader(new FileReader("chocolate.in"));
			out = new PrintWriter("chocolate.out");

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
