#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define MO 1000000007
#define mem(a,s) memset(a,s,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define lop(i,s,e) for(int i=s;i<e;i++)
#define lopi(i,s,e) for(int i=s;i>=e;i--)
#define prina(a,n) for(int i=0;i<=n;i++)cout<<a[i]<<" ";cout<<endl; 
#define prin2da(a,n,m) lop(i,1,n){lop(j,1,m)cout<<a[i][j]<<" ";cout<<endl;}
#define atout(v) for(auto x:v) cout<<x<<" ";cout<<endl;
#define atin(v) for(auto &x:v) cin>>x;
#define vl vector<ll >
#define vi vector<int >
#define lb lower_bound
#define ub upper_bound
#define sort(a) sort(a.begin(),a.end())  
#define mp make_pair
#define all(v) v.begin(),v.end() 
#define pll pair<ll,ll>
using namespace std;

bool check(ll l,ll r,vector<vector<ll>> &p,vector<ll> &b) {
	ll n=p.size();
	lop(i,l,r+1) b[i]=0;
	lop(i,0,n) {
		ll x=p[i][0],y=p[i][1];
		if(x!=-1 and y!=-1) {
			if(y<l or x>r) continue;
			if(y-x!=(r-l+1)/2 or b[x]) return false;
			b[x]=1;
		}
		else if(x!=-1 and y==-1) {
			if(x>r or x<l) continue;
			if(x>=(r+l+1)/2 or b[x]) return false;
			b[x]=1;
		}
		else if(x==-1 and y!=-1) {
			if(y<l or y>r) continue;
			x=y-((r-l+1)/2);
			if(y<(r+l+1)/2 or b[x]) return false;
			b[x]=1;
		}
	}
	return true;
}

void solve() {
	ll n;
	cin>>n;
	vector<vector<ll>> p(n,vector<ll>(2,0));
	vector<bool> dp(2*n+1,false);
	vector<ll> b(2*n+1);
	lop(i,0,n) cin>>p[i][0]>>p[i][1];
	dp[0]=true;
	for(int i=0 ; i<(2*n)+1 ; i+=2) {
		for(int j=i+2 ; j<=(2*n)+1 ; j+=2) {
			//cout<<check(i+1,j,p,b)<<endl;
			dp[j]=dp[j]or(dp[i] and check(i+1,j,p,b));
		}
	}
	//atout(dp);
	cout<<((dp[2*n])?"Yes":"No")<<endl;
	return;
}

int main() {
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	ll t=1;
	while(t--) {
		solve();
	}

	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
/*#include <atcoder/all>
using namespace atcoder;*/
//using mint = modint998244353;
//using mint = modint1000000007;
#pragma endregion
#pragma region macros
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define RREP(i, a, b) for(int i = b - 1; i >= a; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (r).rend()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion

const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); }
ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } 
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}

/*--------------------------------------------------------------------------------------------------------------------------------*/

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	ll n; cin >> n;
	bool ok = false;
	ll a = 1, b = 1;
	for(int i = 1; i < 100; i++){
		a *= 3;
		b = 1;
		if(a > n) break;
		for(int j = 1; j < 100; j++){
			b *= 5;
			if(n < a + b) break;
			if(a + b == n){
				ok = true;
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	if(!ok) cout << -1 << endl;
} 
/*
	* int overflow, array bounds
	* special cases (n=1?)
*/
