// Задача "Шоколад"
// XVIII командный чемпионат школьников Санкт-Петербурга по программированию
// Автор задачи: Виталий Аксенов
// Автор решения: Владимир Ульянцев, ulyantsev@rain.ifmo.ru

uses
    sysutils, Math;
type
    int = longint;
const
    MAXN = 1000;

var
    n, m : int;
    a : array [1..MAXN, 1..MAXN] of int;

procedure read_with_assertions();
var
    i, j : int;
    was : array [1..MAXN * MAXN div 2] of boolean;
begin
    fillchar(was, sizeof(was), 0);

    read(n, m);
    assert((1 <= n) and (n <= MAXN));
    assert((1 <= m) and (m <= MAXN));
    assert(n * m mod 2 = 0);

    for i := 1 to n do begin
        for j := 1 to m do begin
            read(a[i][j]);
            assert((1 <= a[i][j]) and (a[i][j] <= n * m div 2));
            was[a[i][j]] := true;
        end;
    end;

    for i := 1 to n * m div 2 do begin
        assert(was[i])
    end;
end;

var
    i, j : int;
    can_x, can_y : array [1..MAXN] of boolean;
    ans : string;

begin
    assign(input, 'chocolate.in');
    reset(input);
    assign(output, 'chocolate.out');
    rewrite(output);

    read_with_assertions;
    
    for i := 1 to m - 1 do begin
        can_x[i] := true;
    end;

    for i := 1 to n - 1 do begin
        can_y[i] := true;
    end;

    for i := 1 to n do begin
        for j := 1 to m do begin
            if (i > 1) and (a[i - 1][j] = a[i][j]) then begin
                can_y[i - 1] := false;
            end;

            if (j > 1) and (a[i][j - 1] = a[i][j]) then begin
                can_x[j - 1] := false;
            end;
        end;
    end;

    ans := 'No';
    for i := 1 to m - 1 do begin
        if can_x[i] then begin
            ans := 'Yes';
        end;
    end;

    for i := 1 to n - 1 do begin
        if can_y[i] then begin
            ans := 'Yes';
        end;
    end;

    writeln(ans);
    
    close(input);
    close(output);
end.
