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

public class chocolate_nn implements Runnable {
    public static void main(String[] args) {
        new chocolate_nn().run();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        boolean eof;
        String buf;

        public FastScanner(String fileName) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(fileName));
            nextToken();
        }

        public FastScanner(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            nextToken();
        }

        String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    eof = true;
                    break;
                }
            }
            String ret = buf;
            buf = eof ? "-1" : st.nextToken();
            return ret;
        }

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

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

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

        void close() {
            try {
                br.close();
            } catch (Exception e) {

            }
        }

        boolean isEOF() {
            return eof;
        }
    }

    FastScanner sc;
    PrintWriter out;

    private static final String FN = "chocolate";

    public void run() {
        Locale.setDefault(Locale.US);
        try {
            sc = new FastScanner(FN + ".in");
            out = new PrintWriter(FN + ".out");
            solve();
            sc.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    void doAssert(boolean isRight, String s) {
        if (!isRight)
            throw new AssertionError(s);
    }

    void checkChocolate(int[][] a, int n, int m) {
        int[] b = new int[(n * m) >> 1];
        final int[] DX = { 1, 0, -1, 0 };
        final int[] DY = { 0, 1, 0, -1 };
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                b[a[i][j] - 1]++;
                int count = 0;
                for (int dir = 0; dir < DX.length; dir++) {
                    int x = i + DX[dir];
                    int y = j + DY[dir];
                    if (x < 0 || y < 0 || x >= n || y >= m
                            || a[x][y] != a[i][j]) {
                        continue;
                    }
                    count++;
                }
                doAssert(count == 1, "invalid chocolate");
            }
        }
        for (int i = 0; i < b.length; i++) {
            doAssert(b[i] == 2, "invalid chocolate");
        }
    }

    private void solve() {
        int n = sc.nextInt();
        int m = sc.nextInt();
        doAssert((n & m & 1) == 0, "n * m is not even");
        doAssert(1 <= n && n <= 1000 && 1 <= m && m <= 1000,
                "invalid values of n and/or m");
        int[][] a = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
                doAssert(1 <= a[i][j] && a[i][j] <= ((n * m) >> 1),
                        "the number of part of the chocolate is out of range");
            }
        }
        checkChocolate(a, n, m);
        for (int i = 0; i + 1 < n; i++) {
            boolean check = true;
            for (int j = 0; j < m; j++) {
                if (a[i][j] == a[i + 1][j]) {
                    check = false;
                    break;
                }
            }
            if (check) {
                out.println("Yes");
                return;
            }
        }
        for (int j = 0; j + 1 < m; j++) {
            boolean check = true;
            for (int i = 0; i < n; i++) {
                if (a[i][j] == a[i][j + 1]) {
                    check = false;
                    break;
                }
            }
            if (check) {
                out.println("Yes");
                return;
            }
        }
        out.println("No");
    }
}
