#define NOMINMAX
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=(int)b;--i)
#define range(i,a,b,c) for(int i=a;c>0?i<b:i>b;i+=c)

#define chmax(a,b) (a=(a)<(b)?(b):(a))
#define chmin(a,b) (a=(a)>(b)?(b):(a))

#define i1(a) cin>>a;
#define i2(a,b) cin>>a>>b;
#define i3(a,b,c) cin>>a;i2(b,c);

#define p1(a) cout<<a<<endl;
#define p2(a,b) cout<<a<<" ";p1(b);
#define p3(a,b,c) cout<<a<<" ";p2(b, c);

#define abp(o,a,b) p1(((o)?a:b))
#define YEP(x) abp(x,"YES","NO")
#define Yep(x) abp(x,"Yes","No")

#define all(a) begin(a),end(a)
#define ifnot(a) if(!(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE==true
const bool test=true;
#define dump(x) cerr<<#x<<" : "<<(x)<< " "
#define dumpl(x) dump(x)<<endl
#else
const bool test=false;
#define dump(x) 
#define dumpl(x)
#endif

#else
const bool test=false;
#define dump(x) 
#define dumpl(x)
#endif

using ll = int;
using ull = unsigned int;
using ld = long double;

ll dx[]={1,0,-1,0};
ll dy[]={0,1,0,-1};
const ll inf=(ll)1<<60;
const ll undefined=inf;
const ll INFL=(ll)1<<60;
ll mod_n=(ll)1e9+7;
const double eps=1e-10;
typedef long double Real;
// return -1, 0, 1
ll sgn(const Real&r){return(r>eps)-(r<-eps);}
ll sgn(const Real&a,const Real&b) {return sgn(a-b);}

const ll MAX = (ll)2e5 + 5;

vector<string> split(const string&str,char sep){vector<string> v;stringstream ss(str);string buffer;while (getline(ss, buffer, sep)) v.push_back(buffer);return v;}

string join(const vector<string>& v, const string delim = 0){string s;if(!v.empty()){s+=v[0];for(decltype(v.size()) i=1,c=v.size();i<c;++i){if(delim!="")s+=delim;s+=v[i];}}return s;}

string operator*(const string&s,const ll&n){string res="";rep(i,n)res+=s;return res;}

#define sum(a) accumulate(all(a),0ll)

template<typename T>T gcd(T a,T b){T c;while(a!=0){c=a;a=b%a;b=c;};return b;}
#define bit_cnt(n) [](int n){int c=0;while(N){if(N&1)c++;N>>=1;}return c;};

template<typename T>void prll_vec(ostream& o,vector<T> a){rep(i,a.size()-1)o<<a[i]<<" ";o<<a.back()<<endl;}

ll pow_n(ll x,ll n){ll r=1;while(n>0){if(n&1)r=r*x;x=x*x;n>>=1;}return r;}

ll H,W;

#define grid_ng(y,x) (y<0||y>=H||x<0||x>=W)

ll div_ceil(ll a,ll b){ll r=a/b;if(a%b!=0)r++;return r;}


struct Point{ll x,y;bool operator<(const Point&r)const{if(x!=r.x)return x<r.x;return y<r.y;}};



int n, k;
int t[10][10];
bool visited[10];
int visited_n = 0;
int cost = 0;

class Solver {
public:
	int dfs(int curId) {
		if (visited_n == n - 1) {
			return cost + t[curId][0] == k;
		}

		int cnt = 0;
		rep(i, n) {
			if (visited[i] == false) {
				visited[i] = true;
				cost += t[curId][i];
				visited_n++;

				cnt += dfs(i);

				visited[i] = false;
				cost -= t[curId][i];
				visited_n--;
			}
		}

		return cnt;
	}

	void solve() {
		cin >> n >> k;
		rep(i, n) {
			rep(j, n) {
				cin >> t[i][j];
			}
		}
		visited[0] = true;

		cout << dfs(0) << endl;
	}
};

signed main(){srand((unsigned int)time(NULL));cout<<fixed<<setprecision(20);auto ptr=new Solver();ptr->solve();delete ptr;return 0;}
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

map<int,int> m;
int op[205];
int a[205];
int b[205];

bool dp[205][205];
bool dp2[205][205];

bool solve(int start, int end) {
	bool &ret = dp[start][end];
	if (dp2[start][end]){
		return ret;
	}
	dp2[start][end]=true;
	
	int d = (end-start)/2;
	
	bool good = true;
	
	for (int i = start; i+d < end && good; i++){
		if (op[i] || op[i+d]) {
			if (op[i] != i+d) {
				good = false;
			}
		}
		if (m.count(i)){
			if (a[m[i]] != i) {
				good = false;
			}
		}
		if (m.count(i+d)) {
			if (b[m[i+d]] != i+d) {
				good = false;
			}
		}
		if (m.count(i)&&m.count(i+d)){
			if (m[i]!=m[i+d]) {
				good = false;
			}
		}
	}
	
	if (good) {
		return ret = true;
	}
	
	for (int i = start+2; i < end; i+=2){
		if (solve(start,i) && solve(i,end)) {
			return ret = true;
		}
	}
	
	
	return ret = false;
}

bool answer() {
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if (a[i]!=-1) {
			m[a[i]]=i;
			cnt++;
		}
		if (b[i]!=-1) {
			m[b[i]]=i;
			cnt++;
		}
		if (a[i]!=-1 && b[i]!=-1){
			op[a[i]]=b[i];
			op[b[i]]=a[i];
		}
	}
	
	if(cnt!=(int)m.size()) return false;
	
	for (int i = 0; i < n; i++) {
		if (a[i] != -1 && b[i] != -1 && a[i] >= b[i])
			return false;
	}
	
	return solve(1,2*n+1);

}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cout << (answer() ? "Yes" : "No") << "\n";
}
