#include <bits/stdc++.h>
using namespace std;

// 0: top, 1: front, 2:right, 3:back, 4:left, 5:bottom
const vector<vector<string>> dice_map = {
    {"0...",
     "1234",
     "5..."},
    {"0...",
     "1234",
     ".5.."},
    {"0...",
     "1234",
     "..5."},
    {"0...",
     "1234",
     "...5"},
    {".0..",
     "4123",
     ".5.."},
    {".0..",
     "4123",
     "..5."},
    {"...0",
     "2341",
     "..5."},
    {"...0",
     "2341",
     ".5.."},
    {"...0",
     "2341",
     "5..."},
    {"..0.",
     "3412",
     ".5.."},
    {"..0.",
     "3412",
     "5..."},
    {".0..",
     "4123",
     "5..."},
    {"..025",
     "341.."},
    {"025..",
     "..143"},
    {"..02",
     "341.",
     "5..."},
    {"40..",
     ".123",
     "...5"},
    {"..02",
     "341.",
     ".5.."},
    {"40..",
     ".123",
     "..5."},
    {"..02",
     "341.",
     "..5."},
    {"40..",
     ".123",
     ".5.."},
    {"..02",
     ".41.",
     "35.."},
    {"40..",
     ".12.",
     "..53"},
};

vector<string> rot_map(vector<string> const& v) {
    const int n = v.size(), m = v[0].size();
    vector<string> res(m);
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            res[j] += v[n - i - 1][j];
        }
    }
    return res;
};

using dice = string;

constexpr int rot_d[2][6] = {
    {3, 0, 2, 5, 4, 1}, // Front
    {0, 4, 1, 2, 3, 5}, // Side
};

dice rot_dice(dice const& v, int dir) {
    dice res(6, ' ');
    for(int j = 0; j < 6; ++j) {
        res[j] = v[rot_d[dir][j]];
    }
    return res;
}

bool is_valid_dice(dice const& d) {
    bool res = true;
    for(int i = 0; i < 3; ++i) {
        res &= isalpha(d[i]) || isdigit(d[i]);
        res &= d[i + 3] == '#';
    }
    return res;
}

bool check(vector<dice>& ds, int i) {
    bool res = false;
    if(i == 8) {
        res = true;
        for(int j = 0; j < 4; ++j) {
            res &= ds[j][0] == ds[0][0]; // top
            res &= ds[j + 4][0] == ds[4][0]; // bottom
            // side
            res &= ds[j][2] == ds[(j + 1) % 4][1];
            //res &= ds[j + 4][1] == ds[(j + 1) % 4 + 4][2];
            res &= ds[j][1] == ds[j + 4][2] && ds[j][2] == ds[j + 4][1];
        }
        return res;
    } else {
        for(int j = 0; j < 3; ++j) {
            res |= check(ds, i + 1);
            rotate(begin(ds[i]), begin(ds[i]) + 1, end(ds[i]));
        }
    }
    return res;
}

int main() {
    int h, w; cin >> h >> w;
    vector<string> v(h);
    for(auto& s : v) cin >> s;

    { // check1
        map<char, int> cols;
        for(auto const& s : v) {
            for(auto const c : s) {
                if(c == '.' || c == '#') continue;
                cols[c] += 1;
            }
        }
        bool chk = cols.size() == 6u;
        for(auto const& p : cols) {
            chk &= p.second == 4;
        }
        if(!chk) {
            cout << "No" << endl;
            return 0;
        }
    }

    vector<dice> dices;
    auto in_range = [&] (int y, int x) {
        return 0 <= y && y < h && 0 <= x && x < w;
    };
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            for(auto dm : dice_map) {
                string td;
                for(int k = 0; k < 4; ++k, dm = rot_map(dm)) {
                    const int n = dm.size(), m = dm[0].size();
                    if(!in_range(i + n - 1, j + m - 1)) continue;
                    string d(6, '.');
                    for(int y = i; y < i + n; ++y) {
                        for(int x = j; x < j + m; ++x) {
                            if(dm[y - i][x - j] == '.') continue;
                            d[dm[y - i][x - j] - '0'] = v[y][x];
                        }
                    }
                    if(d[0] == '.' || d[0] == '#') {
                        d = rot_dice(rot_dice(d, 0), 0);
                    }
                    for(int l = 0; l < 4; ++l, d = rot_dice(d, 1)) {
                        if(!is_valid_dice(d)) continue;
                        td = d.substr(0, 3);
                    }
                }
                if(!td.empty()) {
                    dices.push_back(td);
                }
            }
        }
    }

    // check
    sort(begin(dices), end(dices));
    bool ans = false;
    do {
        ans |= check(dices, 1);
    } while(!ans && next_permutation(begin(dices) + 1, end(dices)));

    cout << (ans ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3228