#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
//#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int sze = 3e5 + 50, oo = 1e18 + 500, mod = 1e9 + 7;
const double eps = 1e-9, PI = 2 * acos(0.0);
vi vertices[sze];
vi visit(sze, 0);
vc used(sze, false);
vi arr(sze, 0);
int n, m, k;
int A, B;
int cnt = 0;

int a[55][55], b[55][55];

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	/*freopen("stars.in", "r", stdin);
	freopen("stars.out", "w", stdout);*/

	cin >> n >> m;

	vi x = { 1, 0, -1, 0 };
	vi y = { 0, 1, 0, -1 };

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> b[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			for (int z = 0; z < 4; z++)
			{
				int f = i + x[z];
				int s = j + y[z];

				if (f < n && f >= 0 && s < m && s >= 0)
				{
					if (i + j < f + s)
					{
						if (a[i][j] >= a[f][s] && b[i][j] < a[f][s])
						{
							swap(a[i][j], b[i][j]);
						}
					}
					else
					{
						if (a[i][j] <= a[f][s] && b[i][j] > a[f][s])
						{
							swap(a[i][j], b[i][j]);
						}
					}
				}
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			for (int z = 0; z < 4; z++)
			{
				int f = i + x[z];
				int s = j + y[z];

				if (f < n && f >= 0 && s < m && s >= 0)
				{
					if (i + j < f + s)
					{
						if (b[i][j] >= b[f][s] && a[i][j] < b[f][s])
						{
							swap(a[i][j], b[i][j]);
						}
					}
					else
					{
						if (b[i][j] <= b[f][s] && a[i][j] > b[f][s])
						{
							swap(a[i][j], b[i][j]);
						}
					}
				}
			}
		}
	}

	bool fl = true;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m-1; j++)
		{
			if (a[i][j] >= a[i][j + 1] || b[i][j] >= b[i][j + 1])
			{
				fl = false;
				break;
			}
		}
	}

	for (int j = 0; j < m; j++)
	{
		for (int i = 0; i < n-1; i++)
		{
			if (a[i][j] >= a[i+1][j] || b[i][j] >= b[i+1][j])
			{
				fl = false;
				break;
			}
		}
	}

	if (fl)
	{
		cout << "Possible";
	}
	else
	{
		cout << "Impossible";
	}
	return 0;
}


#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
//#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int sze = 3e5 + 50, oo = 1e18 + 500, mod = 1e9 + 7;
const double eps = 1e-9, PI = 2 * acos(0.0);
vi vertices[sze];
vi visit(sze, 0);
vc used(sze, false);
vi arr(sze, 0);
int n, m, k;
int A, B;
int cnt = 0;

int a[55][55], b[55][55];

vi x = { 1, 0, -1, 0 };
vi y = { 0, 1, 0, -1 };

bool check1(int i, int j, int v)
{
	for (int z = 0; z < 4; z++)
	{
		int f = i + x[z];
		int s = j + y[z];

		if (f < n && f >= 0 && s < m && s >= 0)
		{
			if (i + j < f + s)
			{
				if (v >= a[f][s])
				{
					return false;
				}
			}
			else
			{
				if (v <= a[f][s])
				{
					return false;
				}
			}
		}
	}

	return true;
}

bool check2(int i, int j, int v)
{
	for (int z = 0; z < 4; z++)
	{
		int f = i + x[z];
		int s = j + y[z];

		if (f < n && f >= 0 && s < m && s >= 0)
		{
			if (i + j < f + s)
			{
				if (v >= b[f][s])
				{
					return false;
				}
			}
			else
			{
				if (v <= b[f][s])
				{
					return false;
				}
			}
		}
	}

	return true;
}

bool tr(int i, int j)
{
	vi f = { a[i + 1][j], a[i][j], a[i][j + 1] };
	vi s = { b[i + 1][j], b[i][j], b[i][j + 1] };
	for (int mask = 0; mask < 8; mask++)
	{
		vi tf = f;
		vi ts = s;
		if (mask & 1)
		{
			swap(tf[0], ts[0]);
		}

		if (mask & 2)
		{
			swap(tf[1], ts[1]);
		}

		if (mask & 4)
		{
			swap(tf[2], ts[2]);
		}

		if (tf[1] < tf[0] && tf[1] < tf[2] && ts[1] < ts[0] && ts[1] < ts[2])
		{
			a[i + 1][j] = tf[0];
			a[i][j] = tf[1];
			a[i][j+1] = tf[2];

			b[i + 1][j] = ts[0];
			b[i][j] = ts[1];
			b[i][j+1] = ts[2];
			return true;
		}
	}

	return false;
}

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	/*freopen("stars.in", "r", stdin);
	freopen("stars.out", "w", stdout);*/

	cin >> n >> m;

	for (int i = 0; i < 55; i++)
	{
		for (int j = 0; j < 55; j++)
		{
			a[i][j] = oo;
			b[i][j] = oo;
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> b[i][j];
		}
	}

	bool fl = true;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (!tr(i, j))
			{
				fl = false;
				break;
			}
		}
	}

	if (fl)
	{
		cout << "Possible";
	}
	else
	{
		cout << "Impossible";
	}
	return 0;
}


#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
//#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int sze = 3e5 + 50, oo = 1e18 + 500, mod = 1e9 + 7;
const double eps = 1e-9, PI = 2 * acos(0.0);
vi vertices[sze];
vi visit(sze, 0);
vc used(sze, false);
vi arr(sze, 0);
int n, m, k;
int A, B;
int cnt = 0;

int a[55][55], b[55][55];

bool nsw[55][55], sw[55][55];

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	/*freopen("stars.in", "r", stdin);
	freopen("stars.out", "w", stdout);*/

	cin >> n >> m;

	for (int i = 0; i < 55; i++)
	{
		for (int j = 0; j < 55; j++)
		{
			a[i][j] = oo;
			b[i][j] = oo;
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> b[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			sw[i][j] = nsw[i][j] = true;

			if (i > 0)
			{
				sw[i][j] = sw[i - 1][j] && b[i - 1][j] < b[i][j] && a[i - 1][j] < a[i][j];
				sw[i][j] = sw[i][j] || nsw[i - 1][j] && a[i - 1][j] < b[i][j] && b[i - 1][j] < a[i][j];
				nsw[i][j] = sw[i - 1][j] && a[i - 1][j] < b[i][j] && b[i - 1][j] < a[i][j];
				nsw[i][j] = nsw[i][j] || nsw[i - 1][j] && b[i - 1][j] < b[i][j] && a[i - 1][j] < a[i][j];
			}

			if (j > 0)
			{
				sw[i][j] &= (sw[i][j-1] && b[i][j-1] < b[i][j] && a[i][j-1] < a[i][j]
					|| nsw[i][j - 1] && a[i][j - 1] < b[i][j] && b[i][j - 1] < a[i][j]);
				nsw[i][j] &= (sw[i][j-1] && a[i][j - 1] < b[i][j] && b[i][j - 1] < a[i][j]
					|| nsw[i][j - 1] && a[i][j - 1] < a[i][j] && b[i][j - 1] < b[i][j]);
			}
		}
	}

	bool fl = nsw[n - 1][m - 1] || sw[n - 1][m - 1];
	if (fl)
	{
		cout << "Possible";
	}
	else
	{
		cout << "Impossible";
	}
	return 0;
}


#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
//#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int sze = 3e5 + 50, oo = 1e18 + 500, mod = 1e9 + 7;
const double eps = 1e-9, PI = 2 * acos(0.0);
vi vertices[sze];
vi visit(sze, 0);
vc used(sze, false);
vi arr(sze, 0);
int n, m, k;
int A, B;
int cnt = 0;

int a[55][55], b[55][55];

vi x = { 1, 0, -1, 0 };
vi y = { 0, 1, 0, -1 };

bool check1(int i, int j, int v)
{
	for (int z = 0; z < 4; z++)
	{
		int f = i + x[z];
		int s = j + y[z];

		if (f < n && f >= 0 && s < m && s >= 0)
		{
			if (i + j < f + s)
			{
				if (v >= a[f][s])
				{
					return false;
				}
			}
			else
			{
				if (v <= a[f][s])
				{
					return false;
				}
			}
		}
	}

	return true;
}

bool check2(int i, int j, int v)
{
	for (int z = 0; z < 4; z++)
	{
		int f = i + x[z];
		int s = j + y[z];

		if (f < n && f >= 0 && s < m && s >= 0)
		{
			if (i + j < f + s)
			{
				if (v >= b[f][s])
				{
					return false;
				}
			}
			else
			{
				if (v <= b[f][s])
				{
					return false;
				}
			}
		}
	}

	return true;
}

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	/*freopen("stars.in", "r", stdin);
	freopen("stars.out", "w", stdout);*/

	cin >> n >> m;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> b[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			for (int z = 0; z < 4; z++)
			{
				if (check1(i, j, a[i][j]))
				{
					continue;
				}

				if (check1(i, j, b[i][j]) && check2(i, j, a[i][j]))
				{
					swap(a[i][j], b[i][j]);
				}
			}
		}
	}

	bool fl = true;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m-1; j++)
		{
			if (a[i][j] >= a[i][j + 1] || b[i][j] >= b[i][j + 1])
			{
				fl = false;
				break;
			}
		}
	}

	for (int j = 0; j < m; j++)
	{
		for (int i = 0; i < n-1; i++)
		{
			if (a[i][j] >= a[i+1][j] || b[i][j] >= b[i+1][j])
			{
				fl = false;
				break;
			}
		}
	}

	if (fl)
	{
		cout << "Possible";
	}
	else
	{
		cout << "Impossible";
	}
	return 0;
}


#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
//#define endl '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;
#define int long long
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

const int sze = 3e5 + 50, oo = 1e18 + 500, mod = 1e9 + 7;
const double eps = 1e-9, PI = 2 * acos(0.0);
vi vertices[sze];
vi visit(sze, 0);
vc used(sze, false);
vi arr(sze, 0);
int n, m, k;
int A, B;
int cnt = 0;

int a[55][55], b[55][55];

vi x = { 1, 0, -1, 0 };
vi y = { 0, 1, 0, -1 };

bool check1(int i, int j, int v)
{
	for (int z = 0; z < 4; z++)
	{
		int f = i + x[z];
		int s = j + y[z];

		if (f < n && f >= 0 && s < m && s >= 0)
		{
			if (i + j < f + s)
			{
				if (v >= a[f][s])
				{
					return false;
				}
			}
			else
			{
				if (v <= a[f][s])
				{
					return false;
				}
			}
		}
	}

	return true;
}

bool check2(int i, int j, int v)
{
	for (int z = 0; z < 4; z++)
	{
		int f = i + x[z];
		int s = j + y[z];

		if (f < n && f >= 0 && s < m && s >= 0)
		{
			if (i + j < f + s)
			{
				if (v >= b[f][s])
				{
					return false;
				}
			}
			else
			{
				if (v <= b[f][s])
				{
					return false;
				}
			}
		}
	}

	return true;
}

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	/*freopen("stars.in", "r", stdin);
	freopen("stars.out", "w", stdout);*/

	cin >> n >> m;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> b[i][j];
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			for (int z = 0; z < 4; z++)
			{
				if (check1(i, j, a[i][j]))
				{
					continue;
				}

				if (check1(i, j, b[i][j]) && check2(i, j, a[i][j]))
				{
					swap(a[i][j], b[i][j]);
				}
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			for (int z = 0; z < 4; z++)
			{
				if (check2(i, j, b[i][j]))
				{
					continue;
				}

				if (check2(i, j, a[i][j]) && check1(i, j, b[i][j]))
				{
					swap(a[i][j], b[i][j]);
				}
			}
		}
	}

	bool fl = true;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m-1; j++)
		{
			if (a[i][j] >= a[i][j + 1] || b[i][j] >= b[i][j + 1])
			{
				fl = false;
				break;
			}
		}
	}

	for (int j = 0; j < m; j++)
	{
		for (int i = 0; i < n-1; i++)
		{
			if (a[i][j] >= a[i+1][j] || b[i][j] >= b[i+1][j])
			{
				fl = false;
				break;
			}
		}
	}

	if (fl)
	{
		cout << "Possible";
	}
	else
	{
		cout << "Impossible";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100][100],b[100][100];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               scanf("%lld",&a[i][j]);
          }
    }
    for(int i=1;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               scanf("%lld",&b[i][j]);
          }
    }
    ll maxx,minn;
    for(int i=1;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               maxx=max(a[i][j],b[i][j]);
               minn=min(a[i][j],b[i][j]);
               a[i][j]=minn;
               b[i][j]=maxx;
          }
    }
    int flag=1;
    for(int i=1;i<n;i++)
    {
          for(int j=2;j<=m;j++)
          {
               if(a[i][j-1]>=a[i][j]||b[i][j-1]>=b[i][j])
                    flag=0;
          }
    }
    for(int i=2;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               if(a[i-1][j]>=a[i][j]||b[i-1][j]>=b[i][j])
                    flag=0;
          }
    }
    if(flag)
    {
          cout<<"Possible"<<endl;
    }
    else
    {
          cout<<"Impossible"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100][100],b[100][100];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               scanf("%lld",&a[i][j]);
          }
    }
    for(int i=1;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               scanf("%lld",&b[i][j]);
          }
    }
    int maxx,minn;
    for(int i=1;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               maxx=max(a[i][j],b[i][j]);
               minn=min(a[i][j],b[i][j]);
               a[i][j]=minn;
               b[i][j]=maxx;
          }
    }
    int flag=1;
    for(int i=1;i<n;i++)
    {
          for(int j=2;j<=m;j++)
          {
               if(a[i][j-1]>=a[i][j]||b[i-1][j]>=b[i][j])
                    flag=0;
          }
    }
    for(int i=2;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               if(a[i-1][j]>=a[i][j]||b[i-1][j]>=b[i][j])
                    flag=0;
          }
    }
    if(flag)
    {
          cout<<"Possible"<<endl;
    }
    else
    {
          cout<<"Impossible"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100][100],b[100][100];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               scanf("%d",&a[i][j]);
          }
    }
    for(int i=1;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               scanf("%d",&b[i][j]);
          }
    }
    int maxx,minn;
    for(int i=1;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               maxx=max(a[i][j],b[i][j]);
               minn=min(a[i][j],b[i][j]);
               a[i][j]=minn;
               b[i][j]=maxx;
          }
    }
    int flag=1;
    for(int i=1;i<=n;i++)
    {
          for(int j=2;j<=m;j++)
          {
               if(a[i][j-1]>=a[i][j]||b[i][j-1]>=b[i][j])
                    flag=0;
          }
    }
    for(int i=2;i<=n;i++)
    {
          for(int j=1;j<=m;j++)
          {
               if(a[i-1][j]>=a[i][j]||b[i-1][j]>=b[i][j])
                    flag=0;
          }
    }
    if(flag)
    {
          cout<<"Possible"<<endl;
    }
    else
    {
          cout<<"Impossible"<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long int;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a[n][m],b[n][m];
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>a[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>b[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m-1;j++)
    	{
    		if(a[i][j]>=a[i][j+1]||b[i][j]>=b[i][j+1])
    		{
    			if(a[i][j+1]>b[i][j]&&b[i][j+1]>a[i][j])
    			{
    				swap(a[i][j+1],b[i][j+1]);
    			}
    			else if(a[i][j]<b[i][j+1]&&b[i][j]<a[i][j+1])
    			{
    				swap(a[i][j],b[i][j]);
    			}
    			else
    			{
    				cout<<"Impossible"<<endl;
    				return 0;
    			}
    		}
    	}
    }
    vector<int> aa,bb;
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		aa.push_back(a[i][j]);
    		bb.push_back(b[i][j]);
    	}
    }
    for(int i=0;i<n*m-1;i++)
    {
    	if(aa[i]>aa[i+1]||bb[i]>bb[i+1])
    	{
    		cout<<"Impossible"<<endl;
    		return 0;
    	}
    }
    cout<<"Possible"<<endl;

}


#include<bits/stdc++.h>
using namespace std;
using ll = long long int;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a[n][m],b[n][m];
    cout<<"yoa"<<endl;
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>a[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>b[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m-1;j++)
    	{
    		if(a[i][j]>=a[i][j+1]||b[i][j]>=b[i][j+1])
    		{
    			if(a[i][j+1]>b[i][j]&&b[i][j+1]>a[i][j])
    			{
    				swap(a[i][j+1],b[i][j+1]);
    			}
    			else if(a[i][j]<b[i][j+1]&&b[i][j]<a[i][j+1])
    			{
    				swap(a[i][j],b[i][j]);
    			}
    			else
    			{
    				cout<<"Impossible"<<endl;
    				return 0;
    			}
    		}
    	}
    }
    cout<<"Possible"<<endl;

}


#include<bits/stdc++.h>
using namespace std;
using ll = long long int;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a[n][m],b[n][m];
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>a[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>b[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m-1;j++)
    	{
    		if(a[i][j]>=a[i][j+1]||b[i][j]>=b[i][j+1])
    		{
    			if(a[i][j+1]>b[i][j]&&b[i][j+1]>a[i][j])
    			{
    				swap(a[i][j+1],b[i][j+1]);
    			}
    			else if(a[i][j]<b[i][j+1]&&b[i][j]<a[i][j+1])
    			{
    				swap(a[i][j],b[i][j]);
    			}
    			else
    			{
    				cout<<"Impossible"<<endl;
    				return 0;
    			}
    		}
    	}
    }
    cout<<"Possible"<<endl;

}


#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
int a[105][105],b[105][105];
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)cin>>a[i][j];
	for(int i=1;i<=n;i++){
	for(int j=1;j<=m;j++){
	cin>>b[i][j];
	if(a[i][j]>b[i][j])swap(a[i][j],b[i][j]);
	if(a[i][j]<=a[i-1][j]||a[i][j]<=a[i][j-1]||b[i][j]<=b[i-1][j]||b[i][j]<=b[i][j-1])return cout<<"Impossible\n",0;
	}
	}
	cout<<"Possible\n";

}


#include<bits/stdc++.h>
using namespace std;
using ll = long long int;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a[n][m],b[n][m];
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>a[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>b[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		if(a[i][j]<b[i][j])swap(a[i][j],b[i][j]);
    	}
    }
    for(int i=0;i<n-1;i++)
    {
    	for(int j=0;j<m-1;j++)
    	{
    		if(a[i][j]>=a[i][j+1]||a[i][j]>=a[i+1][j]||b[i][j]>=b[i][j+1]||b[i][j]>=b[i+1][j])
    			{
    				cout<<"Impossible"<<endl;
    				return 0;
    			}
    	}
    }
    cout<<"Possible"<<endl;

}


#include<bits/stdc++.h>
using namespace std;
using ll = long long int;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a[n][m],b[n][m];
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>a[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>b[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		if(a[i][j]>b[i][j])swap(a[i][j],b[i][j]);
    	}
    }
    for(int i=0;i<n-1;i++)
    {
    	for(int j=0;j<m-1;j++)
    	{
    		if(a[i][j]>=a[i][j+1]||a[i][j]>=a[i+1][j]||b[i][j]>=b[i][j+1]||b[i][j]>=b[i+1][j])
    			{
    				cout<<"Impossible"<<endl;
    				return 0;
    			}
    	}
    }
    cout<<"Possible"<<endl;

}


#include<bits/stdc++.h>
using namespace std;
using ll = long long int;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a[n][m],b[n][m];
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>a[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		cin>>b[i][j];
    	}
    }
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m-1;j++)
    	{
    		if(a[i][j]>=a[i][j+1]||b[i][j]>=b[i][j+1])
    		{
    			if(a[i][j+1]>b[i][j]&&b[i][j+1]>a[i][j])
    			{
    				swap(a[i][j+1],b[i][j+1]);
    			}
    			else if(a[i][j]<b[i][j+1]&&b[i][j]<a[i][j+1])
    			{
    				swap(a[i][j],b[i][j]);
    			}
    			else
    			{
    				cout<<"Impossible"<<endl;
    				return 0;
    			}
    		}
    	}
    }
    vector<int> aa,bb;
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    	{
    		aa.push_back(a[i][j]);
    		bb.push_back(b[i][j]);
    	}
    }
    for(int i=0;i<n*m-1;i++)
    {
    	if(aa[i]>aa[i+1]||bb[i]>[bb+1])
    	{
    		cout<<"Impossible"<<endl;
    		return 0;
    	}
    }
    cout<<"Possible"<<endl;

}


#include <bits/stdc++.h>
using namespace std;
int m,n;
int a[52][52],b[52][52];
void prin(){
	int i;
	int j;
	cout<<"a:"<<endl;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<"b:"<<endl;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cout<<b[i][j]<<" ";
		}
		cout<<endl;
	}
}
int isout(int x,int y){
	//3:������2����һ�У�1����һ��
	if(x-1>=0&&y-1>=0){
		return 3;
	}
	if(x-1>=0&&y-1<0)
		return 2;
	if(x-1<0&&y-1>=0)
		return 1;
	return 0;

}

int check(int x,int y){
	//�����������ϣ����оͱȽ�
	int flag=isout(x,y);
	if(flag==0){
		return 1;
	}

	if(flag==3&&a[x][y]>a[x-1][y]&&a[x][y]>a[x][y-1]&&b[x][y]>b[x-1][y]&&b[x][y]>b[x][y-1]){
		return 1;
	}
	if(flag==2&&a[x][y]>a[x-1][y]&&b[x][y]>b[x-1][y]){
		return 1;
	}

	if(flag==1&&a[x][y]>a[x][y-1]&&b[x][y]>b[x][y-1]){
		return 1;
	}

	return 0;
}
int main(){
	cin>>n>>m;
	int i,j,t;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>b[i][j];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(!check(i,j)){
				t=a[i][j];
				a[i][j]=b[i][j];
				b[i][j]=t;
		//		prin();
				if(!check(i,j)){
					cout<<"Impossible";
					return 0;
				}
			}
		}
	}

	cout<<"Possible";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int m,n;
long long a[52][52],b[52][52];
void prin(){
	int i;
	int j;
	cout<<"a:"<<endl;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<"b:"<<endl;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cout<<b[i][j]<<" ";
		}
		cout<<endl;
	}
}
int isout(int x,int y){
	//3:������2����һ�У�1����һ��
	if(x-1>=0&&y-1>=0){
		return 3;
	}
	if(x-1>=0&&y-1<0)
		return 2;
	if(x-1<0&&y-1>=0)
		return 1;
	return 0;
}

int check(int x,int y){
	//�����������ϣ����оͱȽ�
	int flag=isout(x,y);
	if(flag==0){
		return 1;
	}

	if(flag==3&&a[x][y]>a[x-1][y]&&a[x][y]>a[x][y-1]&&b[x][y]>b[x-1][y]&&b[x][y]>b[x][y-1]){
		return 1;
	}
	if(flag==2&&a[x][y]>a[x-1][y]&&b[x][y]>b[x-1][y]){
		return 1;
	}
	if(flag==1&&a[x][y]>a[x][y-1]&&b[x][y]>b[x][y-1]){
		return 1;
	}
	return 0;
}
int main(){
	cin>>n>>m;
	int i,j;
	long long t;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>b[i][j];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(!check(i,j)){
				t=a[i][j];
				a[i][j]=b[i][j];
				b[i][j]=t;
		//		prin();
				if(!check(i,j)){
					cout<<"Impossible";
					return 0;
				}
			}
		}
	}

	cout<<"Possible";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define Mod 1125899839733759
#define mod1 193939
#define Base 2269
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

int main()
{
    Speed;
    int n,m,i,j;
    ll a[100][100] , b[100][100];
    cin>>n>>m;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>a[i][j];
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>b[i][j];
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if((i>0 && (a[i][j] <= a[i-1][j] || b[i][j] <= b[i-1][j])) || (j > 0 && (a[i][j] <= a[i][j-1] || b[i][j] <= b[i][j-1])))
                    swap(a[i][j] , b[i][j]);

            if(i > 0)
            {
                if(a[i][j] > a[i-1][j] && b[i][j] > b[i-1][j])
                {
                    if(j>0)
                    {
                        if(a[i][j] > a[i][j-1] && b[i][j] > b[i][j-1])
                            continue;
                        else
                        {
                            cout<<"Impossible"<<endl;
                            return 0;
                        }
                    }
                    continue;
                }
                else
                {
                    cout<<"Impossible"<<endl;
                    return 0;
                }
            }
            if(j > 0)
            {
                if(a[i][j] > a[i][j-1] && b[i][j] > b[i][j-1])
                {
                    if(i>0)
                    {
                        if(a[i][j] > a[i-1][j] && b[i][j] > b[i-1][j] )
                            continue;
                        else
                        {
                            cout<<"Impossible"<<endl;
                            return 0;
                        }
                    }
                    continue;
                }
                else
                {
                    cout<<"Impossible"<<endl;
                    return 0;
                }
            }
        }
        cout<<"Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define Mod 1125899839733759
#define mod1 193939
#define Base 2269
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

int main()
{
    Speed;
    int n,m,i,j;
    ll a[100][100] , b[100][100];
    cin>>n>>m;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>a[i][j];
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>b[i][j];
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(i>0)
                if(a[i][j] < a[i-1][j] || b[i][j] < b[i-1][j])
                    swap(a[i][j] , b[i][j]);

            if(j > 0)
                if(a[i][j] < a[i][j-1] || b[i][j] < b[i][j-1])
                     swap(a[i][j] , b[i][j]);
            if(i > 0)
            {
                if(a[i][j] > a[i-1][j] && b[i][j] > b[i-1][j] )
                {
                    if(j>0)
                    {
                        if(a[i][j] > a[i][j-1] && b[i][j] > b[i][j-1])
                            continue;
                        else
                        {
                            cout<<"Impossible"<<endl;
                            return 0;
                        }
                    }
                    continue;
                }
                else
                {
                    cout<<"Impossible"<<endl;
                    return 0;
                }

            }
            if(j>0)
            {
                if(a[i][j] > a[i][j-1] && b[i][j] > b[i][j-1])
                {
                    if(i>0)
                    {
                        if(a[i][j] > a[i-1][j] && b[i][j] > b[i-1][j] )
                            continue;
                        else
                        {
                            cout<<"Impossible"<<endl;
                            return 0;
                        }
                    }
                    continue;
                }
                else
                {
                    cout<<"Impossible"<<endl;
                    return 0;
                }
            }
        }
        cout<<"Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define Mod 1125899839733759
#define mod1 193939
#define Base 2269
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

int main()
{
    Speed;
    int n,m,i,j;
    ll a[100][100] , b[100][100];
    cin>>n>>m;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>a[i][j];
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>b[i][j];
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(i>0)
                if(a[i][j] <= a[i-1][j] || b[i][j] <= b[i-1][j])
                    swap(a[i][j] , b[i][j]);

            if(j > 0)
                if(a[i][j] <= a[i][j-1] || b[i][j] <= b[i][j-1])
                     swap(a[i][j] , b[i][j]);
            if(i > 0)
            {
                if(a[i][j] > a[i-1][j] && b[i][j] > b[i-1][j] )
                {
                    if(j>0)
                    {
                        if(a[i][j] > a[i][j-1] && b[i][j] > b[i][j-1])
                            continue;
                        else
                        {
                            cout<<"Impossible"<<endl;
                            return 0;
                        }
                    }
                    continue;
                }
                else
                {
                    cout<<"Impossible"<<endl;
                    return 0;
                }

            }
            if(j>0)
            {
                if(a[i][j] > a[i][j-1] && b[i][j] > b[i][j-1])
                {
                    if(i>0)
                    {
                        if(a[i][j] > a[i-1][j] && b[i][j] > b[i-1][j] )
                            continue;
                        else
                        {
                            cout<<"Impossible"<<endl;
                            return 0;
                        }
                    }
                    continue;
                }
                else
                {
                    cout<<"Impossible"<<endl;
                    return 0;
                }
            }
        }
        cout<<"Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define Mod 1125899839733759
#define mod1 193939
#define Base 2269
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

ll a[100][100] , b[100][100];

int main()
{
    Speed;
    int n,m,i,j;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            cin>>a[i][j];
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            cin>>b[i][j];
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        {
            if(a[i][j] > b[i][j])
                    swap(a[i][j] , b[i][j]);

            if(a[i][j] <= a[i-1][j] || b[i][j] <= b[i-1][j] || a[i][j] <= a[i][j-1] || b[i][j] <= b[i][j-1])
            {
                cout<<"Impossible"<<endl;
                return 0;

            }

        }
        cout<<"Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define Mod 1125899839733759
#define mod1 193939
#define Base 2269
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

int main()
{
    Speed;
    int n,m,i,j;
    ll a[100][100] , b[100][100];
    cin>>n>>m;
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>a[i][j];
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            cin>>b[i][j];
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
        {
            if(i>0)
                if(a[i][j] < a[i-1][j] || b[i][j] < b[i-1][j])
                    swap(a[i][j] , b[i][j]);

            if(j > 0)
                if(a[i][j] < a[i][j-1] || b[i][j] < b[i][j-1])
                     swap(a[i][j] , b[i][j]);
            if(i > 0)
            {
                if(a[i][j] > a[i-1][j] && b[i][j] > b[i-1][j] )
                {
                    if(j>0)
                        if(a[i][j] > a[i][j-1] && b[i][j] > b[i][j-1])
                            continue;
                        else
                        {
                            cout<<"Impossible"<<endl;
                            return 0;
                        }
                    continue;
                }
                else
                {
                    cout<<"Impossible"<<endl;
                    return 0;
                }

            }
            if(j>0)
            {
                if(a[i][j] > a[i][j-1] && b[i][j] > b[i][j-1])
                {
                    if(i>0)
                        if(a[i][j] > a[i-1][j] && b[i][j] > b[i-1][j] )
                            continue;
                        else
                        {
                            cout<<"Impossible"<<endl;
                            cout<<i<<" "<<j;
                            return 0;
                        }
                    continue;
                }
                else
                {
                    cout<<"Impossible"<<endl;
                    return 0;
                }
            }
        }
        cout<<"Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define Mod 1125899839733759
#define mod1 193939
#define Base 2269
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

ll a[100][100] , b[100][100];

int main()
{
    Speed;
    int n,m,i,j;
    cin>>n>>m;
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            cin>>a[i][j];
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
            cin>>b[i][j];
    for(i=1;i<=n;i++)
        for(j=1;j<=m;j++)
        {
            if(a[i][j] <= a[i-1][j] || b[i][j] <= b[i-1][j] || a[i][j] <= a[i][j-1] || b[i][j] <= b[i][j-1])
                    swap(a[i][j] , b[i][j]);

            if(a[i][j] <= a[i-1][j] || b[i][j] <= b[i-1][j] || a[i][j] <= a[i][j-1] || b[i][j] <= b[i][j-1])
            {
                cout<<"Impossible"<<endl;
                return 0;

            }

        }
        cout<<"Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, m, temp;
    cin >> n >> m;
    vector<long long> t(m + 1);
    vector<vector<long long> > a;
    vector<vector<long long> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }
    for(int i = 1; i < n + 1; ++i){
        for(int j = 1; j < m + 1; ++j){
            if(a[i][j] > b[i][j])
                swap(a[i][j], b[i][j]);
        }
    }
    cout << endl;
    for(auto i: a){
        for(int j: i)
            cout << j << " ";
        cout << endl;
    }
    cout << endl;
    for(auto i: b){
        for(int j: i)
            cout << j << " ";
        cout << endl;
    }
    for(int i = 1; i < n + 1; ++i){
        for(int j = 1; j < m + 1; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j]){
                cout << "Impossible";
                return 0;
            }
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j]){
                cout << "Impossible";
                return 0;
            }
        }
    }

    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, m, temp;
    cin >> n >> m;
    vector<long long> t(m + 1);
    vector<vector<long long> > a;
    vector<vector<long long> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }
    for(int i = 1; i < n + 1; ++i){
        for(int j = 1; j < m + 1; ++j){
            if(a[i][j] > b[i][j])
                swap(a[i][j], b[i][j]);
        }
    }

    for(int i = 1; i < n + 1; ++i){
        for(int j = 1; j < m + 1; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j]){
                cout << "Impossible";
                return 0;
            }
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j]){
                cout << "Impossible";
                return 0;
            }
        }
    }

    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m, temp;
    cin >> n >> m;
    vector<int> t(m + 1);
    vector<vector<int> > a;
    vector<vector<int> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 1; i < n; ++i){
        for(int j = 1; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j]){
                if(b[i][j] > a[i][j - 1] && b[i][j] > a[i - 1][j]){
                    if(a[i][j] > b[i][j - 1] && a[i][j] > b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                    else{
                        cout << "Impossible";
                        return 0;
                    }
                }
                else{
                    cout << "Impossible";
                    return 0;
                }
            }
        }
    }
    for(int i = 1; i < n; ++i){
        for(int j = 1; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j]){
                if(a[i][j] > b[i][j - 1] && a[i][j] > b[i - 1][j]){
                    if(b[i][j] > a[i][j - 1] && b[i][j] > a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                    else{
                        cout << "Impossible";
                        return 0;
                    }
                }
                else{
                    cout << "Impossible";
                    return 0;
                }
            }
        }
    }
    cout << "Possible";
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{

    unsigned n, m;
    cin >> n >> m;

    int a[n][m], b[n][m];
    for(unsigned i = 0; i < n; ++i)
        for(unsigned j = 0; j < m; ++j)
            cin >> a[i][j];
    for(unsigned i = 0; i < n; ++i)
        for(unsigned j = 0; j < m; ++j)
            cin >> b[i][j];

    for(unsigned i = 0; i < n; ++i) {
        for(unsigned j = 0; j < m; ++j) {
            bool ma = false, mb = false;
            if(j) {
                if(a[i][j] <= a[i][j - 1])
                    ma = true;
                if(b[i][j] <= b[i][j - 1])
                    mb = true;
            }
            if(i) {
                if(a[i][j] <= a[i - 1][j])
                    ma = true;
                if(b[i][j] <= b[i - 1][j])
                    mb = true;
            }
            if(ma || mb) {
                ma = false, mb = false;
                swap(a[i][j], b[i][j]);
                if(j) {
                    if(a[i][j] <= a[i][j - 1])
                        ma = true;
                    if(b[i][j] <= b[i][j - 1])
                        mb = true;
                }
                if(i) {
                    if(a[i][j] <= a[i - 1][j])
                        ma = true;
                    if(b[i][j] <= b[i - 1][j])
                        mb = true;
                }
            }
            if(ma || mb) {
                cout << "Impossible";
                return 0;
            }
        }
    }
    cout << "Possible" << endl;
//    for(unsigned i = 0; i < n; ++i) {
//        for(unsigned j = 0; j < m; ++j)
//            cout << a[i][j] << " ";
//        cout << endl;
//    }
//    cout << endl;
//    for(unsigned i = 0; i < n; ++i) {
//        for(unsigned j = 0; j < m; ++j)
//            cout << b[i][j] << " ";
//        cout << endl;
//    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m, temp;
    cin >> n >> m;
    vector<int> t(m + 1);
    vector<vector<int> > a;
    vector<vector<int> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 1; i < a.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])
                if(b[i][j] > a[i][j - 1] && b[i][j] <= a[i - 1][j])
                    if(a[i][j] < b[i][j - 1] && a[i][j] <= b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    for(int i = 1; i < b.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])
                if(a[i][j] > b[i][j - 1] && a[i][j] <= b[i - 1][j])
                    if(b[i][j] < a[i][j - 1] && b[i][j] <= a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, m, temp;
    cin >> n >> m;
    vector<long long> t(m + 1);
    vector<vector<long long> > a;
    vector<vector<long long> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }
    for(int i = 1; i < n + 1; ++i){
        for(int j = 1; j < m + 1; ++j){
            if(a[i][j] > b[i][j])
                swap(a[i][j], b[i][j]);
        }
    }

    for(int i = 1; i < n + 1; ++i){
        for(int j = 1; j < m + 1; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j]){
                cout << "Impossible";
                return 0;
            }
        }
    }

    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m, temp;
    cin >> n >> m;
    vector<int> t(m + 1);
    vector<vector<int> > a;
    vector<vector<int> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 1; i < a.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])
                if(b[i][j] < a[i][j - 1] && b[i][j] < a[i - 1][j])
                    if(a[i][j] < b[i][j - 1] && a[i][j] < b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    for(int i = 1; i < b.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])
                if(a[i][j] < b[i][j - 1] && a[i][j] < b[i - 1][j])
                    if(b[i][j] < a[i][j - 1] && b[i][j] < a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m, temp;
    cin >> n >> m;
    vector<int> t(m + 1);
    vector<vector<int> > a;
    vector<vector<int> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 0; i < a.size(); ++i){
        for(int j = 0 ; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])
                if(b[i][j] > a[i][j - 1] && b[i][j] <= a[i - 1][j])
                    if(a[i][j] < b[i][j - 1] && a[i][j] <= b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    for(int i = 0; i < b.size(); ++i){
        for(int j = 0 ; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])
                if(a[i][j] > b[i][j - 1] && a[i][j] <= b[i - 1][j])
                    if(b[i][j] < a[i][j - 1] && b[i][j] <= a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m, temp;
    cin >> n >> m;
    vector<int> t(m + 1);
    vector<vector<int> > a;
    vector<vector<int> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 1; i < a.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])
                if(b[i][j] < a[i][j - 1] && b[i][j] <= a[i - 1][j])
                    if(a[i][j] < b[i][j - 1] && a[i][j] <= b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    for(int i = 1; i < b.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])
                if(a[i][j] < b[i][j - 1] && a[i][j] <= b[i - 1][j])
                    if(b[i][j] < a[i][j - 1] && b[i][j] <= a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, m, temp;
    cin >> n >> m;
    vector<long long> t(m + 1);
    vector<vector<long long> > a;
    vector<vector<long long> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 1; i < a.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])
                if(b[i][j] > a[i][j - 1] && b[i][j] <= a[i - 1][j])
                    if(a[i][j] < b[i][j - 1] && a[i][j] <= b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    for(int i = 1; i < b.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])
                if(a[i][j] > b[i][j - 1] && a[i][j] <= b[i - 1][j])
                    if(b[i][j] < a[i][j - 1] && b[i][j] <= a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m, temp;
    cin >> n >> m;
    vector<int> t(m + 1);
    vector<vector<int> > a;
    vector<vector<int> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 1; i < a.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])
                if(b[i][j] > a[i][j - 1] && b[i][j] > a[i - 1][j]){
                    if(a[i][j] > b[i][j - 1] && a[i][j] > b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                    else{
                        cout << "Impossible";
                        return 0;
                    }
                }
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    for(int i = 1; i < b.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])
                if(a[i][j] > b[i][j - 1] && a[i][j] > b[i - 1][j]){
                    if(b[i][j] > a[i][j - 1] && b[i][j] > a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                    else{
                        cout << "Impossible";
                        return 0;
                    }
                }
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n, m, temp;
    cin >> n >> m;
    vector<long long> t(m + 1);
    vector<vector<long long> > a;
    vector<vector<long long> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 1; i < a.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])
                if(b[i][j] > a[i][j - 1] && b[i][j] > a[i - 1][j]){
                    if(a[i][j] > b[i][j - 1] && a[i][j] > b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                    else{
                        cout << "Impossible";
                        return 0;
                    }
                }
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    for(int i = 1; i < b.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])
                if(a[i][j] > b[i][j - 1] && a[i][j] > b[i - 1][j]){
                    if(b[i][j] > a[i][j - 1] && b[i][j] > a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                    else{
                        cout << "Impossible";
                        return 0;
                    }
                }
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m, temp;
    cin >> n >> m;
    vector<int> t(m + 1);
    vector<vector<int> > a;
    vector<vector<int> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 1; i < a.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])
                if(b[i][j] > a[i][j - 1] && b[i][j] < a[i - 1][j])
                    if(a[i][j] > b[i][j - 1] && a[i][j] < b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    for(int i = 1; i < b.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])
                if(a[i][j] > b[i][j - 1] && a[i][j] < b[i - 1][j])
                    if(b[i][j] > a[i][j - 1] && b[i][j] < a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m, temp;
    cin >> n >> m;
    vector<int> t(m + 1);
    vector<vector<int> > a;
    vector<vector<int> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 1; i < a.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])
                if(b[i][j] >= a[i][j - 1] && b[i][j] <= a[i - 1][j])
                    if(a[i][j] <= b[i][j - 1] && a[i][j] <= b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    for(int i = 1; i < b.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])
                if(a[i][j] >= b[i][j - 1] && a[i][j] <= b[i - 1][j])
                    if(b[i][j] <= a[i][j - 1] && b[i][j] <= a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    cout << "Possible";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, m, temp;
    cin >> n >> m;
    vector<int> t(m + 1);
    vector<vector<int> > a;
    vector<vector<int> > b;
    a.push_back(t);
    b.push_back(t);
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        a.push_back(t);
    }
    for(int i = 0; i < n; ++i){
        t.clear();
        t.push_back(0);
        for(int j = 0; j < m; ++j){
            cin >> temp;
            t.push_back(temp);
        }
        b.push_back(t);
    }

    for(int i = 1; i < a.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(a[i][j] <= a[i][j - 1] || a[i][j] <= a[i - 1][j])
                if(b[i][j] > a[i][j - 1] && b[i][j] < a[i - 1][j])
                    if(a[i][j] < b[i][j - 1] && a[i][j] < b[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    for(int i = 1; i < b.size(); ++i){
        for(int j = 1; j < m; ++j){
            if(b[i][j] <= b[i][j - 1] || b[i][j] <= b[i - 1][j])
                if(a[i][j] > b[i][j - 1] && a[i][j] < b[i - 1][j])
                    if(b[i][j] < a[i][j - 1] && b[i][j] < a[i - 1][j])
                        swap(b[i][j], a[i][j]);
                else{
                    cout << "Impossible";
                    return 0;
                }
        }
    }
    cout << "Possible";
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<list>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
typedef long double ld;
#define mem(x) memset(x, 0, sizeof(x))
#define me(x) memset(x, -1, sizeof(x))
#define fo(i,n) for(i=0; i<n; i++)
#define sc(x) scanf("%lld", &x)
#define pr(x) printf("%lld\n", x)
#define pri(x) printf("%lld ", x)
#define lowbit(x) x&-x
const ll MOD = 1e18 +7;
const ll N = 6e6 +5;
ll a[100][100], b[100][100];
int main()
{
    ll i, j ,k=1, l, r;
    ll n, m, t;
    cin>>n>>m;
    for(i=1; i<=n; i++) a[i][m+1]=MOD;
    for(i=1; i<=m; i++) a[n+1][i]=MOD;
    for(i=1; i<=n; i++) b[i][m+1]=MOD;
    for(i=1; i<=m; i++) b[n+1][i]=MOD;
    for(i=1; i<=n; i++)
        for(j=1; j<=m; j++) cin>>a[i][j];
    for(i=1; i<=n; i++)
        for(j=1; j<=m; j++) cin>>b[i][j];
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
        {
            if(a[i][j]>b[i][j])
                swap(a[i][j], b[i][j]);
        }
    }
    for(i=1; i<=n; i++)
        for(j=1; j<=m; j++)
        {
            if(b[i][j]<=b[i][j-1] || b[i][j]>=b[i][j+1] || b[i][j]<=b[i-1][j] || b[i][j]>=b[i+1][j])
                return cout<<"Impossible"<<endl, 0;

            if(a[i][j]<=a[i][j-1] || a[i][j]>=a[i][j+1] || a[i][j]<=a[i-1][j] || a[i][j]>=a[i+1][j])
                return cout<<"Impossible"<<endl, 0;
        }
    cout<<"Possible"<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<list>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;
typedef long double ld;
#define mem(x) memset(x, 0, sizeof(x))
#define me(x) memset(x, -1, sizeof(x))
#define fo(i,n) for(i=0; i<n; i++)
#define sc(x) scanf("%lld", &x)
#define pr(x) printf("%lld\n", x)
#define pri(x) printf("%lld ", x)
#define lowbit(x) x&-x
const ll MOD = 1e18 +7;
const ll N = 6e6 +5;
ll a[100][100], b[100][100];
int main()
{
    ll i, j ,k=1, l, r;
    ll n, m, t;
    cin>>n>>m;
    for(i=1; i<=n; i++) a[i][m+1]=MOD;
    for(i=1; i<=m; i++) a[n+1][i]=MOD;
    for(i=1; i<=n; i++) b[i][m+1]=MOD;
    for(i=1; i<=m; i++) b[n+1][i]=MOD;
    for(i=1; i<=n; i++)
        for(j=1; j<=m; j++) cin>>a[i][j];
    for(i=1; i<=n; i++)
        for(j=1; j<=m; j++) cin>>b[i][j];
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
        {
            if(a[i][j]<=a[i][j-1] || a[i][j]<=a[i-1][j])
                swap(a[i][j], b[i][j]);
        }
    }
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)
        {
            if(b[i][j]<=b[i][j-1] || b[i][j]<=b[i-1][j])
                swap(a[i][j], b[i][j]);
        }
    }
    for(i=1; i<=n; i++)
        for(j=1; j<=m; j++)
        {
            if(b[i][j]<=b[i][j-1] || b[i][j]>=b[i][j+1] || b[i][j]<=b[i-1][j] || b[i][j]>=b[i+1][j])
                return cout<<"Impossible"<<endl, 0;

            if(a[i][j]<=a[i][j-1] || a[i][j]>=a[i][j+1] || a[i][j]<=a[i-1][j] || a[i][j]>=a[i+1][j])
                return cout<<"Impossible"<<endl, 0;
        }
    cout<<"Possible"<<endl;
    return 0;
}


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

#define x first.first
#define y first.second

int main ()
{
  //freopen("Input.txt","r",stdin);
  //freopen("Output.txt","w",stdout);
  long long n, m;
  cin>>n>>m;
  long long l[n], r[n];
  long long sol[n-1];
  pair <pair <long long, long long>, long long> isla[n-1];
  cin>>l[0]>>r[0];
  for(int i=1;i<n;i++)
	{
		cin>>l[i]>>r[i];
		isla[i-1].x=l[i]-r[i-1];
		isla[i-1].y=r[i]-l[i-1];
		isla[i-1].second=i-1;
	}
  pair <long long, long long> a[n-1];
	for(int i=0;i<m;i++)
	{
		cin>>a[i].first;
		a[i].second=i;
	}
	sort(isla, isla+n-2);
	sort(a, a+m-1);

	/*
	for(int i=0;i<n-1;i++)
		cout<<isla[i].x<<' '<<isla[i].y<<" - "<<isla[i].second<<endl;
	for(int i=0;i<m;i++)
		cout<<a[i].first<<' '<<a[i].second<<endl;
	*/

	int e=0;
	for(int i=0;i<n-1;i++)
	{
		while(a[e].first<isla[i].x or a[e].first>isla[i].y)
		{
			e++;
			if(e>m-2)
			{
				//cout<<"e "<<e<<' '<<a[e].first<<" - "<<isla[i].x<<' '<<isla[i].y<<endl;
				cout<<"No"<<endl;
				return 0;
			}
		}
		//cerr<<"Sol "<<i<<": "<<isla[i].second<<' '<<a[e].second<<endl;
		sol[isla[i].second]=a[e].second;
		e++;
		if(i<n-2 and e>m-2)
		{
			//cout<<"e "<<e<<' '<<a[e].first<<" - "<<isla[i].x<<' '<<isla[i].y<<endl;
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl<<sol[0]+1;
	for(int i=1;i<n-1;i++)
		cout<<' '<<sol[i]+1;
	cout<<endl;
  return 0;
}


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

#define x first.first
#define y first.second

int main ()
{
  //freopen("Input.txt","r",stdin);
  //freopen("Output.txt","w",stdout);
  long long n, m;
  cin>>n>>m;
  long long l[n], r[n];
  long long sol[n-1];
  pair <pair <long long, long long>, long long> isla[n-1];
  cin>>l[0]>>r[0];
  for(int i=1;i<n;i++)
    {
        cin>>l[i]>>r[i];
        isla[i-1].x=l[i]-r[i-1];
        isla[i-1].y=r[i]-l[i-1];
        isla[i-1].second=i-1;
    }
  pair <long long, long long> a[m];
    for(int i=0;i<m;i++)
    {
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(isla, isla+n-1);
    sort(a, a+m);
    int e=0;
    for(int i=0;i<n-1;i++)
    {
        while(a[e].first<isla[i].x or a[e].first>isla[i].y)
        {
            e++;
            if(e>m-2)
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
        sol[isla[i].second]=a[e].second;
        e++;
        if(i<n-2 and e>m-2)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl<<sol[0]+1;
    for(int i=1;i<n-1;i++)
        cout<<' '<<sol[i]+1;
    cout<<endl;
  return 0;
}


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

#define x first.first
#define y first.second

int main ()
{
  //freopen("Input.txt","r",stdin);
  //freopen("Output.txt","w",stdout);
  long long n, m;
  cin>>n>>m;
  long long l[n], r[n];
  long long sol[n-1];
  pair <pair <long long, long long>, long long> isla[n-1];
  cin>>l[0]>>r[0];
  for(int i=1;i<n;i++)
    {
        cin>>l[i]>>r[i];
        isla[i-1].x=l[i]-r[i-1];
        isla[i-1].y=r[i]-l[i-1];
        isla[i-1].second=i-1;
        //cerr<<"i: "<<i-1<<' '<<i-1<<endl;
    }
    long long asdf;
    multiset<pair<long long,int> > a;
    for(int i=0;i<m;i++)
    {
            cin>>asdf;
            a.insert(make_pair(asdf,i));
    }
    sort(isla, isla+n-1);
    multiset <pair <long long, int> >::iterator it;
    for(int i=0;i<n-1;i++)
    {
        it=a.lower_bound(make_pair(isla[i].x,0));
        if(it->first>isla[i].y or it==a.end())
        {
            cout<<"No"<<endl;
            return 0;
        }
        sol[isla[i].second]=it->second;
        a.erase(it);
    }
    cout<<"Yes"<<endl<<sol[0]+1;
    for(int i=1;i<n-1;i++)
        cout<<' '<<sol[i]+1;
    cout<<endl;
  return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stdio.h>
#include<map>
using namespace std;
struct r{
    long long val;
    long long index;
};
struct s{
    long long start;
    long long end;
    long long index;
};
bool operator<(s x,s y){
    if(x.end<y.end)return true;
    else if(x.end==y.end && x.start<y.start)return true;
    return false;
}

bool operator<(r x,r y){
    if(x.val<y.val)return true;
    return false;
}
int main()
{
    long long n,m;
    cin>>n>>m;
    vector<s> imp;
    vector<long long> ans(n,-1);
    s temp;
    cin>>temp.start>>temp.end;
    temp.index=1;
    for(long long i=1;i<n;i++){
    long long l,r,temp1;
    cin>>l>>r;
    temp1=temp.start;
    temp.start=l-temp.end;
    temp.end=r-temp1;
    imp.push_back(temp);
    //cout<<temp.start<<" "<<temp.end<<endl;
    temp.start=l;
    temp.end=r;
    temp.index++;
    }
    sort(imp.begin(),imp.end());
    multimap<long long,int> myMap;
    for(int i=0;i<m;i++){
        long long templ;
        cin>>templ;
        myMap.insert(std::make_pair(templ,i+1));
    }
    multimap<long long,int>::iterator it;
        for(int i=0;i<imp.size();i++){
        it=myMap.find(imp[i].start);
        if(it==myMap.end()){
            it = myMap.upper_bound(imp[i].start);
            if(it==myMap.end()){cout<<"No";return 0;}
        }
        if(imp[i].end>=(*it).first)ans[imp[i].index]=(*it).second;
        else{cout<<"No";return 0;}
        myMap.erase(it);
    }
    cout<<"Yes\n";
    for(int i=1;i<n;i++){
        cout<<ans[i]<<" ";
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stdio.h>
using namespace std;
struct r{
    long long val;
    long long index;
};
struct s{
    long long start;
    long long end;
    long long index;
};
bool operator<(s x,s y){
    if(x.start<y.start)return true;
    else if(x.start==y.start && x.end<y.end)return true;
    return false;
}

bool operator<(r x,r y){
    if(x.val<y.val)return true;
    return false;
}
int main()
{
    long long n,m;
    cin>>n>>m;
    vector<s> imp;
    vector<long long> ans(n-1,-1);
    s temp;
    cin>>temp.start>>temp.end;
    temp.index=1;
    for(long long i=1;i<n;i++){
        long long l,r,temp1;
        cin>>l>>r;
        temp1=temp.start;
        temp.start=l-temp.end;
        temp.end=r-temp1;
        imp.push_back(temp);
        //cout<<r<<" "<<temp.start<<" "<<temp.end<<endl;
        temp.start=l;
        temp.end=r;
        temp.index++;
    }
    sort(imp.begin(),imp.end());
    vector<r> bridge(m);
    for(long long i=0;i<m;i++){
        cin>>bridge[i].val;
        bridge[i].index=i;
    }

    sort(bridge.begin(),bridge.end());
    long long is=0,br=0;

    while(true){
        if(is==n-1)break;
        if(br==m){cout<<"No";return 0;}
        if(bridge[br].val<imp[is].start)br++;
        else if(bridge[br].val>imp[is].end){cout<<"No";return 0;}
        else {
            ans[imp[is].index-1]=bridge[br].index;
            br++;
            is++;
        }
    }
    cout<<"Yes\n";
    for(long long i=0;i<n-1;i++)cout<<ans[i]+1<<" ";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stdio.h>
using namespace std;
struct r{
    long long val;
    long long index;
};
struct s{
    long long start;
    long long end;
    long long index;
};
bool operator<(s x,s y){
    if(x.end<y.end)return true;
    else if(x.end==y.end && x.start<y.start)return true;
    return false;
}

bool operator<(r x,r y){
    if(x.val<y.val)return true;
    return false;
}
int main()
{
    long long n,m;
    cin>>n>>m;
    vector<s> imp;
    vector<long long> ans(n-1,-1);
    s temp;
    cin>>temp.start>>temp.end;
    temp.index=1;
    for(long long i=1;i<n;i++){
        long long l,r,temp1;
        cin>>l>>r;
        temp1=temp.start;
        temp.start=l-temp.end;
        temp.end=r-temp1;
        imp.push_back(temp);
        //cout<<temp.start<<" "<<temp.end<<endl;
        temp.start=l;
        temp.end=r;
        temp.index++;
    }
    sort(imp.begin(),imp.end());
    vector<r> bridge(m);
    for(long long i=0;i<m;i++){
        cin>>bridge[i].val;
        bridge[i].index=i;
    }

    sort(bridge.begin(),bridge.end());
    long long is=n-2,br=m-1;

    while(true){

        if(is==-1)break;
        if(br==-1){cout<<"No";return 0;}
        if(bridge[br].val>imp[is].end)br--;
        else if(bridge[br].val<imp[is].start){cout<<"No";return 0;}
        else {
            ans[imp[is].index-1]=bridge[br].index;
            br--;
            is--;
        }
    }
    cout<<"Yes\n";
    for(long long i=0;i<n-1;i++)cout<<ans[i]+1<<" ";
    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<stdio.h>
using namespace std;
struct r{
    long long val;
    long long index;
};
struct s{
    long long start;
    long long end;
    long long index;
};
bool operator<(s x,s y){
    if(x.end<y.end)return true;
    else if(x.end==y.end && x.start<y.start)return true;
    return false;
}

bool operator<(r x,r y){
    if(x.val<y.val)return true;
    return false;
}
int main()
{
    long long n,m;
    cin>>n>>m;
    vector<s> imp;
    vector<long long> ans(n-1,-1);
    s temp;
    cin>>temp.start>>temp.end;
    temp.index=1;
    for(long long i=1;i<n;i++){
        long long l,r,temp1;
        cin>>l>>r;
        temp1=temp.start;
        temp.start=l-temp.end;
        temp.end=r-temp1;
        imp.push_back(temp);
        cout<<temp.start<<" "<<temp.end<<endl;
        temp.start=l;
        temp.end=r;
        temp.index++;
    }
    sort(imp.begin(),imp.end());
    vector<r> bridge(m);
    for(long long i=0;i<m;i++){
        cin>>bridge[i].val;
        bridge[i].index=i;
    }

    sort(bridge.begin(),bridge.end());
    long long is=n-2,br=m-1;

    while(true){

        if(is==-1)break;
        if(br==-1){cout<<"No";return 0;}
        if(bridge[br].val>imp[is].end)br--;
        else if(bridge[br].val<imp[is].start){cout<<"No";return 0;}
        else {
            ans[imp[is].index-1]=bridge[br].index;
            br--;
            is--;
        }
    }
    cout<<"Yes\n";
    for(long long i=0;i<n-1;i++)cout<<ans[i]+1<<" ";
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
/*3 7
1 3
5 6
9 13
2 2 3 3 5 5 8*/
const int N = 2e5+100;
struct Node{
   __int64 l,r;
   int id;
   bool friend operator<(const Node&aa,const Node bb)
   {
         if(aa.r == bb.r){
            return aa.l > bb.l;
         }
         return aa.r < bb.r;
   }
}line[N],deal[N];
int n,m,ans[N];
int father[N];

struct node{
 __int64 val;
 int id;
 bool friend operator<(const node&aa,const node bb)
   {
        return aa.val < bb.val;
   }
}a[N];
int Find(long long x)
{
    if(father[x] == x)return father[x];
    return father[x] = Find(father[x]);
}
int lower_Find(__int64 val)
{
    int l = 1,r = m;
    if(val<=a[1].val)return 1;
    if(val>a[m].val)return m+1;
    while(l<=r){
        int mid = (l+r)/2;
        if(a[mid].val>=val)r = mid-1;
        else l = mid+1;
    }
    return r+1;
}
int upper_Find(__int64 val)
{
    int l = 1,r = m;
    if(val<a[1].val)return 0;
    if(val>a[m].val)return m;
    while(l<=r){
        int mid = (l+r)/2;
        if(a[mid].val>val)r = mid-1;
        else l = mid+1;
    }
    return r;
}
void sovle()
{
    bool flag = true;
    for(int i=0;i<=m+1;i++)father[i] = i;
    for(int i=1;i<=n-1 ; i++){
        long long val = line[i+1].l-line[i].r;
        long long y = line[i+1].r-line[i].l;

        deal[i].l= lower_Find(val);
        deal[i].r = upper_Find(y);
        if(deal[i].l>m||deal[i].r<=0){
            flag = false;
            break;
        }
        deal[i].id = i;
        //printf("qq%I64d %I64d %I64d\n",y,deal[i].l,deal[i].r);
    }
    if(!flag){
        printf("No\n");
        return ;
    }
    sort(deal+1,deal+n);
    int num = 1;
    for(int i=1;i<=m&num<=n-1;i++){
        if(deal[num].r == i){
            while(num<=n-1&&deal[num].r==i){
                int fx = Find(deal[num].l);
                if(fx<=i){
                    //printf("as %d %d\n",fx,deal[i].id);
                    ans[deal[num].id] = a[fx].id;
                    father[fx] = fx+1;
                }else {
                    flag = false;
                    break;
                }
                num ++;
            }
            if(flag == false)break;
        }
    }
    if(num<=n-1)flag = false;
    if(flag == false)printf("No\n");
    else {
        printf("Yes\n");
        printf("%d",ans[1]);
        for(int i=2; i <=n-1;i++)
            printf(" %d",ans[i]);
        printf("\n");
    }
}

int main()
{
    while(scanf("%d%d",&n,&m)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%I64d%I64d",&line[i].l,&line[i].r);
        }
        for(int i=1;i<=m;i++){
            scanf("%I64d",&a[i].val);
            a[i].id = i;
        }
        if(n-1>m){
            printf("No\n");
            continue;
        }
        sort(line+1,line+n+1);
        sort(a+1,a+m+1);
        sovle();
    }
    return 0 ;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
/*3 7
1 3
5 6
9 13
2 2 3 3 5 5 8*/
const int N = 2e5+100;
struct Node{
   __int64 l,r;
   int id;
   bool friend operator<(const Node&aa,const Node bb)
   {
         if(aa.r == bb.r){
            return aa.l > bb.l;
         }
         return aa.r < bb.r;
   }
}line[N],deal[N];
int n,m,ans[N];

stack<int>sta;
struct node{
 __int64 val;
 int id;
 bool friend operator<(const node&aa,const node bb)
   {
        return aa.val < bb.val;
   }
}a[N];

int lower_Find(__int64 val)
{
    int l = 1,r = m;
    if(val<=a[1].val)return 1;
    if(val>a[m].val)return m+1;
    while(l<=r){
        int mid = (l+r)/2;
        if(a[mid].val>=val)r = mid-1;
        else l = mid+1;
    }
    return r+1;
}
int upper_Find(__int64 val)
{
    int l = 1,r = m;
    if(val<a[1].val)return 0;
    if(val>a[m].val)return m;
    while(l<=r){
        int mid = (l+r)/2;
        if(a[mid].val>val)r = mid-1;
        else l = mid+1;
    }
    return r;
}
void sovle()
{
    bool flag = true;
    for(int i=1;i<=n-1 ; i++){
        long long val = line[i+1].l-line[i].r;
        long long y = line[i+1].r-line[i].l;

        deal[i].l= lower_Find(val);
        deal[i].r = upper_Find(y);
        if(deal[i].l>m||deal[i].r<=0){
            flag = false;
            break;
        }
        deal[i].id = i;
        //printf("qq%I64d %I64d %I64d\n",y,deal[i].l,deal[i].r);
    }
    if(!flag){
        printf("No\n");
        return ;
    }
    while(!sta.empty())sta.pop();
    sort(deal+1,deal+n);
    int num = 1;
    for(int i=1;i<=m&num<=n-1;i++){
        sta.push(i);
        if(deal[num].r == i){
            while(num<=n-1&&deal[num].r==i){
                if(sta.empty()){
                    flag = false;
                    break;
                }
                int u = sta.top();
                if(deal[num].l<=u&&deal[num].r>=u){
                     ans[deal[num].id] = a[u].id;
                     sta.pop();
                }else {
                    flag = false;
                    break;
                }
                num ++;
            }
            if(flag == false)break;
        }
    }
    if(num<=n-1)flag = false;
    if(flag == false)printf("No\n");
    else {
        printf("Yes\n");
        printf("%d",ans[1]);
        for(int i=2; i <=n-1;i++)
            printf(" %d",ans[i]);
        printf("\n");
    }
}

int main()
{
    while(scanf("%d%d",&n,&m)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%I64d%I64d",&line[i].l,&line[i].r);
        }
        for(int i=1;i<=m;i++){
            scanf("%I64d",&a[i].val);
            a[i].id = i;
        }
        if(n-1>m){
            printf("No\n");
            continue;
        }
        sort(line+1,line+n+1);
        sort(a+1,a+m+1);
        sovle();
    }
    return 0 ;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
using namespace std;

const int N = 2e5+100;
struct Node{
   __int64 l,r;
   int id;
   bool friend operator<(const Node&aa,const Node bb)
   {
         if(aa.r == bb.r){
            return aa.l > bb.l;
         }
         return aa.r < bb.r;
   }
}line[N],deal[N];
int n,m,ans[N];
bool vis[N];
stack<int>sta;
struct node{
 __int64 val;
 int id;
 bool friend operator<(const node&aa,const node bb)
   {
        return aa.val < bb.val;
   }
}a[N];

int lower_Find(__int64 val)
{
    int l = 1,r = m;
    if(val<=a[1].val)return 1;
    if(val>a[m].val)return m+1;
    while(l<=r){
        int mid = (l+r)/2;
        if(a[mid].val>=val)r = mid-1;
        else l = mid+1;
    }
    return r+1;
}
int upper_Find(__int64 val)
{
    int l = 1,r = m;
    if(val<a[1].val)return 1;
    if(val>a[m].val)return m;
    while(l<=r){
        int mid = (l+r)/2;
        if(a[mid].val>val)r = mid-1;
        else l = mid+1;
    }
    return r;
}
void sovle()
{

    bool flag = true;

    for(int i=1;i<=n-1 ; i++){
        long long val = line[i+1].l-line[i].r;
        long long y = line[i+1].r-line[i].l;

        deal[i].l= lower_Find(val);
        if(deal[i].l>m){
            flag = false;
            break;
        }
        deal[i].r = upper_Find(y);
        deal[i].id = i;
    }
    if(!flag){
        printf("No\n");
        return ;
    }

    sort(deal+1,deal+n);
    int num = 1;
    for(int i=1;i<=m&num<=n-1;i++){
        sta.push(i);
        if(deal[num].r == i){
            while(num<=n-1&&deal[num].r==i){
                if(sta.empty()){
                    flag = false;
                    break;
                }
                int u = sta.top();
                if(deal[num].l<=u&&deal[num].r>=u){
                     ans[deal[num].id] = a[u].id;
                     sta.pop();
                }else {
                    flag = false;
                    break;
                }
                num ++;
            }
            if(flag == false)break;
        }
    }

    if(flag == false)printf("No\n");
    else {
        printf("Yes\n");
        printf("%d",ans[1]);
        for(int i=2; i <=n-1;i++)
            printf(" %d",ans[i]);
        printf("\n");
    }
}

int main()
{
    while(scanf("%d%d",&n,&m)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%I64d%I64d",&line[i].l,&line[i].r);
        }
        for(int i=1;i<=m;i++){
            scanf("%I64d",&a[i].val);
            a[i].id = i;
        }
        if(n-1>m){
            printf("No\n");
            continue;
        }
        sort(line+1,line+n+1);
        sort(a+1,a+m+1);
        sovle();
    }
    return 0 ;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
using namespace std;

const int N = 2e5+100;
struct Node{
   __int64 l,r;
   int id;
   bool friend operator<(const Node&aa,const Node bb)
   {
         if(aa.r == bb.r){
            return aa.l > bb.l;
         }
         return aa.r < bb.r;
   }
}line[N],deal[N];
int n,m,ans[N];
bool vis[N];
stack<int>sta;
__int64 a[N];

int lower_Find(__int64 val)
{
    int l = 1,r = m;
    if(val<=a[1])return 1;
    if(val>a[m])return m+1;
    while(l<=r){
        int mid = (l+r)/2;
        if(a[mid]>=val)r = mid-1;
        else l = mid+1;
    }
    return r+1;
}
int upper_Find(__int64 val)
{
    int l = 1,r = m;
    if(val<a[1])return 1;
    if(val>a[m])return m;
    while(l<=r){
        int mid = (l+r)/2;
        if(a[mid]>val)r = mid-1;
        else l = mid+1;
    }
    return r;
}
void sovle()
{

    bool flag = true;

    for(int i=1;i<=n-1 ; i++){
        long long val = line[i+1].l-line[i].r;
        long long y = line[i+1].r-line[i].l;

        deal[i].l= lower_Find(val);
        if(deal[i].l>m){
            flag = false;
            break;
        }
        deal[i].r = upper_Find(y);
        deal[i].id = i;
    }
    if(!flag){
        printf("No\n");
        return ;
    }

    sort(deal+1,deal+n);
    int num = 1;
    for(int i=1;i<=m&num<=n-1;i++){
        sta.push(i);
        if(deal[num].r == i){
            while(num<=n-1&&deal[num].r==i){
                if(sta.empty()){
                    flag = false;
                    break;
                }
                int u = sta.top();
                if(deal[num].l<=u&&deal[num].r>=u){
                     ans[deal[num].id] = u;
                     sta.pop();
                }else {
                    flag = false;
                    break;
                }
                num ++;
            }
            if(flag == false)break;
        }
    }

    if(flag == false)printf("No\n");
    else {
        printf("Yes\n");
        printf("%d",ans[1]);
        for(int i=2; i <=n-1;i++)
            printf(" %d",ans[i]);
        printf("\n");
    }
}

int main()
{
    while(scanf("%d%d",&n,&m)!=EOF){
        for(int i=1;i<=n;i++){
            scanf("%I64d%I64d",&line[i].l,&line[i].r);
        }
        for(int i=1;i<=m;i++)
            scanf("%I64d",&a[i]);
        if(n-1>m){
            printf("No\n");
            continue;
        }
        sort(line+1,line+n+1);
        sort(a+1,a+m+1);
        sovle();
    }
    return 0 ;
}


#include <cstdio>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;

const int MAXN = 200100;

struct event {
	llint a,b,velicina,tip,in1,in2;

	event(){}

	event(llint x,llint y, llint z,llint i1,llint i2) {
		a = x;
		b = y;
		velicina = b - a + 1;
		tip = z;
		in1 = i1;
		in2 = i2;
	}

	friend bool operator < (event a,event b) {
		if (a.a != b.a) return a.a < b.a;
		if (a.tip != b.tip) return a.tip < b.tip;
		return a.in1 < b.in1;
	}
};

set <pair <llint,llint> > s;
set <pair <llint,llint> >::iterator it;

vector <event> v;

llint n,m;
llint a,b;

int main()  {
	scanf("%I64d %I64d",&n,&m);

	llint preva, prevb;

	if (n - 1 > m) {
		printf("No\n");
		return 0;
	}

	for (llint i = 0; i < n; i++) {
		scanf("%I64d %I64d",&a,&b);
		if (i == 0) {
			preva = a;
			prevb = b;
			continue;
		}

		v.push_back(event(a - prevb, b - preva, -1, i - 1, i));
		v.push_back(event(b - preva, a - prevb, 4, i - 1, i));
		preva = a;
		prevb = b;
	}

	for (llint i = 0; i < m; i++) {
		scanf("%I64d",&a);
		v.push_back(event(a,a, 1, i + 1, -1));
	}

	sort(v.begin(),v.end());
	llint sol[MAXN];

	for (llint i = 0; i < (llint)v.size(); i++) {
		event x = v[i];

		if (x.tip == 1) {
			if ((int)s.size() == 0) continue;
			it = s.begin();

			sol[it -> second] = x.in1;
			s.erase(it);
		}
		else if (x.tip == -1) {
			s.insert(make_pair(x.velicina,x.in1));
		}
		else {
			if ((int)s.size() != 0 && s.find(make_pair(x.a - x.b + 1, x.in1)) != s.end()) {
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");

	for (llint i = 0; i < n - 1; i++)
		printf("%I64d ",sol[i]);
	printf("\n");
	return 0;
}


#include <cstdio>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;

const int MAXN = 200100;

struct event {
	llint a,b,velicina,tip,in1,in2;

	event(){}

	event(llint x,llint y, llint z,llint i1,llint i2) {
		a = x;
		b = y;
		velicina = b - a + 1;
		tip = z;
		in1 = i1;
		in2 = i2;
	}

	friend bool operator < (event a,event b) {
		if (a.a != b.a) return a.a < b.a;
		if (a.b != b.b) return a.b < b.b;
		return a.in1 < b.in1;
	}
};

set <pair <llint,llint> > s;
set <pair <llint,llint> >::iterator it;

vector <event> v;

llint n,m;
llint a,b;

int main()  {
	scanf("%I64d %I64d",&n,&m);

	llint preva, prevb;

	if (n - 1 > m) {
		printf("No\n");
		return 0;
	}

	for (llint i = 0; i < n; i++) {
		scanf("%I64d %I64d",&a,&b);
		if (i == 0) {
			preva = a;
			prevb = b;
			continue;
		}

		v.push_back(event(a - prevb, b - preva, -1, i - 1, i));
		preva = a;
		prevb = b;
	}

	sort(v.begin(),v.end());

	for (llint i = 0; i <m; i++) {
    	scanf("%I64d",&a);
    	s.insert(make_pair(a,i));
    }

    llint sol[MAXN];

    for (llint i = 0; i < (llint)v.size(); i++) {
    	event x = v[i];

    	if ((int)s.size() == 0) {
    		printf("No\n");
    		return 0;
    	}
    	it = s.upper_bound(make_pair(x.b,(llint)MAXN));

    	if (it != s.begin()) it--;

    	if (it -> first > x.b || it -> first < x.a) {
    		printf("No\n");
    		return 0;
    	}

    	sol[x.in1] = it -> second + 1;
    	s.erase(it);
    }

	printf("Yes\n");

	for (llint i = 0; i < n - 1; i++)
		printf("%I64d ",sol[i]);
	printf("\n");
	return 0;
}


#include <cstdio>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;

const int MAXN = 200100;

struct event {
	llint a,b,velicina,tip,in1,in2;

	event(){}

	event(llint x,llint y, llint z,llint i1,llint i2) {
		a = x;
		b = y;
		velicina = b - a + 1;
		tip = z;
		in1 = i1;
		in2 = i2;
	}

	friend bool operator < (event a,event b) {
		if (a.a != b.a) return a.a < b.a;
		if (a.tip != b.tip) return a.tip < b.tip;
		return a.in1 < a.in2;
	}
};

set <pair <llint,llint> > s;
set <pair <llint,llint> >::iterator it;

vector <event> v;

llint n,m;
llint a,b;

int main()  {
	scanf("%I64d %I64d",&n,&m);

	llint preva, prevb;

	for (llint i = 0; i < n; i++) {
		scanf("%I64d %I64d",&a,&b);
		if (i == 0) {
			preva = a;
			prevb = b;
			continue;
		}

		v.push_back(event(a - prevb, b - preva, -1, i - 1, i));
		v.push_back(event(b - preva, a - prevb, 4, i - 1, i));
		preva = a;
		prevb = b;
	}

	for (llint i = 0; i < m; i++) {
		scanf("%I64d",&a);
		v.push_back(event(a,a, 1, i + 1, -1));
	}

	sort(v.begin(),v.end());
	llint sol[MAXN];

	for (llint i = 0; i < (llint)v.size(); i++) {
		event x = v[i];

		if (x.tip == 1) {
			if ((llint)s.size() == 0) continue;
			it = s.begin();

			sol[it -> second] = x.in1;
			s.erase(it);
		}
		else if (x.tip == -1) {
			s.insert(make_pair(x.velicina,x.in1));
		}
		else {
			if (s.find(make_pair(x.a - x.b + 1, x.in1)) != s.end()) {
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");

	for (llint i = 0; i < n - 1; i++)
		printf("%I64d ",sol[i]);
	printf("\n");
	return 0;
}


#include <cstdio>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;

const int MAXN = 200100;

struct event {
	llint a,b,velicina,tip,in1,in2;

	event(){}

	event(llint x,llint y, llint z,llint i1,llint i2) {
		a = x;
		b = y;
		velicina = b - a + 1;
		tip = z;
		in1 = i1;
		in2 = i2;
	}

	friend bool operator < (event a,event b) {
		if (a.b != b.b) return a.b < b.b;
		if (a.a != b.a) return a.a < b.a;
		return a.in1 < b.in1;
	}
};

set <pair <llint,llint> > s;
set <pair <llint,llint> >::iterator it;

vector <event> v;

llint n,m;
llint a,b;

int main()  {
	scanf("%I64d %I64d",&n,&m);

	llint preva, prevb;

	if (n - 1 > m) {
		printf("No\n");
		return 0;
	}

	for (llint i = 0; i < n; i++) {
		scanf("%I64d %I64d",&a,&b);
		if (i == 0) {
			preva = a;
			prevb = b;
			continue;
		}

		v.push_back(event(a - prevb, b - preva, -1, i - 1, i));
		preva = a;
		prevb = b;
	}

	sort(v.begin(),v.end());

	for (llint i = 0; i <m; i++) {
    	scanf("%I64d",&a);
    	s.insert(make_pair(a,i));
    }

    llint sol[MAXN];

    for (llint i = 0; i < (llint)v.size(); i++) {
    	event x = v[i];

    	if ((int)s.size() == 0) {
    		printf("No\n");
    		return 0;
    	}
    	it = s.lower_bound(make_pair(x.a,0));

    	if (it -> first > x.b || it -> first < x.a) {
    		printf("No\n");
    		return 0;
    	}

    	sol[x.in1] = it -> second + 1;
    	s.erase(it);
    }

	printf("Yes\n");

	for (llint i = 0; i < n - 1; i++)
		printf("%I64d ",sol[i]);
	printf("\n");
	return 0;
}


#include <cstdio>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;

const int MAXN = 200100;

struct event {
	llint a,b,velicina,tip,in1,in2;

	event(){}

	event(llint x,llint y, llint z,llint i1,llint i2) {
		a = x;
		b = y;
		velicina = b - a + 1;
		tip = z;
		in1 = i1;
		in2 = i2;
	}

	friend bool operator < (event a,event b) {
		if (a.a != b.a) return a.a < b.a;
		if (a.tip != b.tip) return a.tip < b.tip;
		return a.in1 < b.in1;
	}
};

set <pair <llint,llint> > s;
set <pair <llint,llint> >::iterator it;

vector <event> v;

llint n,m;
llint a,b;

int main()  {
	scanf("%I64d %I64d",&n,&m);

	llint preva, prevb;

	for (llint i = 0; i < n; i++) {
		scanf("%I64d %I64d",&a,&b);
		if (i == 0) {
			preva = a;
			prevb = b;
			continue;
		}

		v.push_back(event(a - prevb, b - preva - 1, -1, i - 1, i));
		v.push_back(event(b - preva, a - prevb, 4, i - 1, i));
		preva = a;
		prevb = b;
	}

	for (llint i = 0; i < m; i++) {
		scanf("%I64d",&a);
		v.push_back(event(a,a, 1, i + 1, -1));
	}

	sort(v.begin(),v.end());
	llint sol[MAXN];

	for (llint i = 0; i < (llint)v.size(); i++) {
		event x = v[i];

		if (x.tip == 1) {
			if ((int)s.size() == 0) continue;
			it = s.begin();

			sol[it -> second] = x.in1;
			s.erase(it);
		}
		else if (x.tip == -1) {
			s.insert(make_pair(x.velicina,x.in1));
		}
		else {
			if ((int)s.size() != 0 && s.find(make_pair((x.a -1) - x.b + 1, x.in1)) != s.end()) {
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");

	for (llint i = 0; i < n - 1; i++)
		printf("%I64d ",sol[i]);
	printf("\n");
	return 0;
}


#include <cstdio>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;

const int MAXN = 200100;

struct event {
	llint a,b,velicina,tip,in1,in2;

	event(){}

	event(llint x,llint y, llint z,llint i1,llint i2) {
		a = x;
		b = y;
		velicina = b - a + 1;
		tip = z;
		in1 = i1;
		in2 = i2;
	}

	friend bool operator < (event a,event b) {
		if (a.a != b.a) return a.a < b.a;
		if (a.velicina != b.velicina) return a.velicina < b.velicina;
		return a.in1 < b.in1;
	}
};

set <pair <llint,llint> > s;
set <pair <llint,llint> >::iterator it;

vector <event> v;

llint n,m;
llint a,b;

int main()  {
	scanf("%I64d %I64d",&n,&m);

	llint preva, prevb;

	if (n - 1 > m) {
		printf("No\n");
		return 0;
	}

	for (llint i = 0; i < n; i++) {
		scanf("%I64d %I64d",&a,&b);
		if (i == 0) {
			preva = a;
			prevb = b;
			continue;
		}

		v.push_back(event(a - prevb, b - preva, -1, i - 1, i));
		preva = a;
		prevb = b;
	}

	sort(v.begin(),v.end());

	for (llint i = 0; i <m; i++) {
    	scanf("%I64d",&a);
    	s.insert(make_pair(a,i));
    }

    llint sol[MAXN];

    for (llint i = 0; i < (llint)v.size(); i++) {
    	event x = v[i];

    	if ((int)s.size() == 0) {
    		printf("No\n");
    		return 0;
    	}
    	it = s.lower_bound(make_pair(x.a,0));
    	if (it == s.end() || it -> first > x.b) {
    		printf("No\n");
    		return 0;
    	}

    	sol[x.in1] = it -> second + 1;
    	s.erase(it);
    }

	printf("Yes\n");

	for (llint i = 0; i < n - 1; i++)
		printf("%I64d ",sol[i]);
	printf("\n");
	return 0;
}


#include <cstdio>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long llint;

const int MAXN = 200100;

struct event {
	llint a,b,velicina,tip,in1,in2;

	event(){}

	event(llint x,llint y, llint z,llint i1,llint i2) {
		a = x;
		b = y;
		velicina = b - a + 1;
		tip = z;
		in1 = i1;
		in2 = i2;
	}

	friend bool operator < (event a,event b) {
		if (a.a != b.a) return a.a < b.a;
		if (a.tip != b.tip) return a.tip < b.tip;
		return a.in1 < b.in1;
	}
};

set <pair <llint,llint> > s;
set <pair <llint,llint> >::iterator it;

vector <event> v;

llint n,m;
llint a,b;

int main()  {
	scanf("%I64d %I64d",&n,&m);

	llint preva, prevb;

	for (llint i = 0; i < n; i++) {
		scanf("%I64d %I64d",&a,&b);
		if (i == 0) {
			preva = a;
			prevb = b;
			continue;
		}

		v.push_back(event(a - prevb, b - preva, -1, i - 1, i));
		v.push_back(event(b - preva, a - prevb, 4, i - 1, i));
		preva = a;
		prevb = b;
	}

	for (llint i = 0; i < m; i++) {
		scanf("%I64d",&a);
		v.push_back(event(a,a, 1, i + 1, -1));
	}

	sort(v.begin(),v.end());
	llint sol[MAXN];

	for (llint i = 0; i < (llint)v.size(); i++) {
		event x = v[i];

		if (x.tip == 1) {
			if ((int)s.size() == 0) continue;
			it = s.begin();

			sol[it -> second] = x.in1;
			s.erase(it);
		}
		else if (x.tip == -1) {
			s.insert(make_pair(x.velicina,x.in1));
		}
		else {
			if ((int)s.size() != 0 && s.find(make_pair(x.a - x.b + 1, x.in1)) != s.end()) {
				printf("No\n");
				return 0;
			}
		}
	}

	printf("Yes\n");

	for (llint i = 0; i < n - 1; i++)
		printf("%I64d ",sol[i]);
	printf("\n");
	return 0;
}