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

public class chocolate_sm_wrong {
	final int[] DX = {
			-1,
			1,
			0,
			0
	};
	final int[] DY = {
			0,
			0,
			-1,
			1
	};

	void solve() throws IOException {
		int n = nextInt();
		assert 1 <= n && n <= 20;
		int m = nextInt();
		assert 1 <= m && m <= 20;
		assert m % 2 == 0 || n % 2 == 0;
		int[][] a = new int[n][m];
		int[] cnt = new int[n * m / 2];
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[0].length; j++) {
				a[i][j] = nextInt();
				assert 1 <= a[i][j] && a[i][j] <= n * m / 2;
				cnt[a[i][j] - 1]++;
			}
			assert !st.hasMoreTokens();
		}
		for (int i = 0; i < m * n / 2; i++) {
			assert cnt[i] == 2;
		}
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[0].length; j++) {
				boolean ok = false;
				for (int it = 0; it < DX.length; it++) {
					if (in(i + DX[it], j + DY[it], n, m)) {
						ok |= a[i][j] == a[i + DX[it]][j + DY[it]];
					}
				}
				assert ok;
			}
		}
		int[][] b = new int[m][n];
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[0].length; j++) {
				b[j][i] = a[i][j];
			}
		}
		if (check(a) || check(b)) {
			out.println("Yes");
		} else {
			out.println("No");
		}

	}

	private boolean in(int x, int y, int n, int m) {
		return x >= 0 && x < n && y >= 0 && y < m;
	}

	private boolean check(int[][] a) {
		for (int i = 0; i < Math.min(a.length, a[0].length) - 1; i++) {
			boolean ok = true;
			for (int j = 0; j < Math.min(a.length, a[0].length); j++) {
				if (a[i][j] == a[i + 1][j]) {
					ok = false;
					break;
				}
			}
			if (ok) {
				return true;
			}
		}
		return false;
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	final String filename = "chocolate";

	public void run() {
		try {
			br = new BufferedReader(new FileReader(filename + ".in"));
			out = new PrintWriter(filename + ".out");
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	String nextToken() {
		try {
			while (st == null || !st.hasMoreTokens()) {
				String s = br.readLine();
				if (s == null) {
					return null;
				}
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		} catch (IOException e) {
			throw new RuntimeException();
		}
	}

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

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

	public static void main(String[] args) {
		new chocolate_sm_wrong().run();
	}
}
