#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
#include <typeinfo>

std::vector<std::string> fill_road(int height, int width) {
	std::vector<std::string> state(height, std::string(width, '.'));
	for (auto i = 0; i < height; i += 2) {
		if (i > 0) {
			if (i % 4 != 0) state[i - 1][width - 1] = '#';
			else state[i - 1][2] = '#';
		}
		for (auto j = 2; j < width; ++j) state[i][j] = '#';
	}
	for (auto i = 0; i < height; ++i) state[i][0] = '#';
	state[0][1] = '#';
	state[height - 1][1] = '#';
	return state;
}
void overlay(std::vector<std::string>& base, const std::vector<std::string>& over) {
	for (auto i = 0; i < base.size(); ++i) for (auto j = 0; j < base[i].size(); ++j) {
		if (base[i][j] == '.') base[i][j] = over[i][j];
	}
}
struct Coordinate {
	int x, y;
	std::vector<Coordinate> neighbors() const {
		return std::vector<Coordinate>{ Coordinate{x + 1, y}, Coordinate{x - 1, y}, Coordinate{x, y + 1}, Coordinate{x, y - 1} };
	}
};
int main() {
	int height, width; std::cin >> height >> width;
	std::vector<std::string> state(height); for (auto& line : state) std::cin >> line;
	int h, w; 
	for (auto i = 0; i < height; ++i) for (auto j = 0; j < width; ++j) {
		if (state[i][j] == '@') {
			h = i; w = j; break;
		}
	}
	overlay(state, fill_road(height, width));
	for (const auto neighbor : Coordinate{ h, w }.neighbors()) {
		if (0 <= neighbor.x && neighbor.x < height && 0 <= neighbor.y && neighbor.y < width && state[neighbor.x][neighbor.y] == '#') {
			std::queue<Coordinate> queue; queue.push(neighbor);
			while (!queue.empty()) {
				auto top = queue.front(); queue.pop();
				if (0 <= top.x && top.x < height && 0 <= top.y && top.y < width && state[top.x][top.y] == '#') {
					state[top.x][top.y] = '.';
					for (const auto next : top.neighbors()) {
						queue.push(next);
					}
				}
			}
			break;
		}
	}
	for (const auto line : state) std::cout << line << '\n';
}
