#pragma comment (linker, "/STACK:256000000")

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_NONSTDC_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <memory.h>
#include <sstream>
#include <cassert>
#include <ctime>
#include <complex>
#include <random>
#include <bitset>

using namespace std;

typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
typedef long double ldouble;
typedef pair<int, int> pii;
typedef pair<int64, int64> pll;
typedef pair<uint64, uint64> puu;
typedef pair<pii, pii> piiii;

#define pb push_back
#define sq(x) ((x)*(x))
#define tmin(x,y,z) (min(min((x),(y)),(z)))
#define rand32() (((unsigned int)(rand()) << 16) | (unsigned int)(rand()))
#define rand64() (((unsigned int64)(rand32()) << 16) | (unsigned int64)(rand32()))
#define bit(mask, b) ((mask >> b) & 1)
#define biton(mask, bit) (mask | (((uint32)(1)) << bit))
#define bitoff(mask, bit) (mask & (~(((uint32)(1)) << bit)))
#define bitputon(mask, bit) (mask |= (((uint32)(1)) << bit))
#define bitputoff(mask, bit) (mask &= (~(((uint32)(1)) << bit)))
#define FAIL() (*((int*)(0)))++
#define INF ((int)(1e9) + 1337)
#define LINF ((int64)(1e18))
#define EPS 1e-13
#define PI (3.1415926535897932384626433832795)
#define y1 yy1
#define y0 yy0
#define j0 jj0
//#define MOD 1000000007LL
#define HMOD 1234567913LL
#define HMOD2 1000000007LL
#define HBASE 1000003
#define REV2 500000004


//#ifdef _MY_DEBUG
//    #define HMOD 1000000007
//    #define HBASE (1000003LL)
//#else
//    #define HMOD ((int64)(1e18) + 3LL)
//    #define HBASE (1000037LL)
//#endif
#define MAX 2000000000
mt19937 ggen;

int h, w;
char a[600][600];
char b[600][600];
char r[600][600];

void solve()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            cin >> a[i][j];
    memset(b, '.', sizeof b);
    memset(r, '.', sizeof r);
    for (int i = 0; i < w; i++)
        b[0][i] = b[h - 1][i] = '#';
    for (int i = 0; i < h; i++)
        b[i][0] = b[i][w - 1] = '#';
    for (int i = 1; i < h - 1; i += 2)
    {
        for (int j = 1; j < w - 1; j++)
            r[i][j] = '#';
        if (i + 1 != h - 1)
        {
            if (a[i + 1][1] == '.' && a[i + 1][w - 2] == '.')
            {
                r[i + 1][1] = '#';
                for (int j = 2; j < w - 1; j++)
                    b[i + 1][j] = '#';
            }
            else if (a[i + 1][1] == '#')
            {
                r[i + 1][1] = '#';
                for (int j = 1; j < w - 2; j++)
                    b[i + 1][j] = '#';
            }
            else
            {
                r[i + 1][w - 2] = '#';
                for (int j = 2; j < w - 1; j++)
                    b[i + 1][j] = '#';
            }
        }
    }
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            if (a[i][j] == '#')
                b[i][j] = r[i][j] = '#';
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            if (a[i][j] == '.' && b[i][j] == '#' && r[i][j] == '#')
                FAIL();
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
            cout << r[i][j];
        cout << '\n';
    }
    cout << '\n';
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
            cout << b[i][j];
        cout << '\n';
    }
}

#define TASK "substr"
int main()  
{
    //testgen(100000, 100000);// return 0;
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _MY_DEBUG
    freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout);
#else
    //freopen(TASK ".in", "rt", stdin); freopen(TASK ".out", "wt", stdout);
#endif
    //stresstest(5, 7, 100); return 0;
    ggen = mt19937(13);

    //int start = clock();
    solve();

    return 0;
}

Measured memory_bytes: 1792