#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <sstream>
#include <cmath>
#include <tuple>
#include <limits>

#define ll long long
#define ull unsigned long long
#define ci cin
#define co cout
#define cl endl
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define mp(i,j) make_pair(i,j)
#define mt(i,j,k) make_tuple(i,j,k)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vs vector<string>
#define vd vector<double>
#define vii vector<pair<int,int>>
#define vdd vector<pair<double,double>>
#define vvii vector<vector<pair<int,int>>>
#define pb(i) push_back(i)
#define pf(i) push_front(i)
#define ppb() pop_back()
#define ppf() pop_front()
#define sz() size()
#define bk() back()
#define ft() front()
#define fs first
#define sc second
#define max(i,j) ((i>j)?(i):(j))
#define min(i,j) ((i<j)?(i):(j))
#define rvs(i) reverse(i.begin(),i.end())
#define rvsc(i,c) reverse(i.begin(),i.begin()+c)
#define ssort(i) sort(i.begin(),i.end())
#define ers erase
#define ins insert
#define bgn begin
#define clr clear
#define asn assign
#define gln(s) getline(cin,s)
#define rep(i,n) \
  for(int i=0;i<n;++i)
#define repc(i,c,n) \
  for(int i=c;i<n;++i)
#define repr(i,c,n) \
  for(int i=c;i>=n;--i)
#define inf (2147483647/2)
#define pi 3.141592653589793
#define eps 0.00000000001
#define lwb lower_bound

using namespace std;

int main(){
  int n,k;
  ci>>n>>k;
  int b=0,g=0;
  vii res;
  repc(i,1,k)repc(j,1,k){
    int tb=j,tg=j+i;
    if(tg>k) break;
    if(b==tb) swap(tb,tg);
    b=tb;g=tg;
    res.pb(mp(b,g));
    if(res.sz()==n) goto ret;
  }
  :ret
  if(res.sz()==n){
    co<<"YES"<<cl;
    for(auto& p:res)
      co<<p.fs<<" "<<p.sc<<cl;
  }else{
    co<<"NO"<<cl;
  }
  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <sstream>
#include <cmath>
#include <tuple>
#include <limits>

#define ll long long
#define ull unsigned long long
#define ci cin
#define co cout
#define cl endl
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define mp(i,j) make_pair(i,j)
#define mt(i,j,k) make_tuple(i,j,k)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vs vector<string>
#define vd vector<double>
#define vii vector<pair<int,int>>
#define vdd vector<pair<double,double>>
#define vvii vector<vector<pair<int,int>>>
#define pb(i) push_back(i)
#define pf(i) push_front(i)
#define ppb() pop_back()
#define ppf() pop_front()
#define sz() size()
#define bk() back()
#define ft() front()
#define fs first
#define sc second
#define max(i,j) ((i>j)?(i):(j))
#define min(i,j) ((i<j)?(i):(j))
#define rvs(i) reverse(i.begin(),i.end())
#define rvsc(i,c) reverse(i.begin(),i.begin()+c)
#define ssort(i) sort(i.begin(),i.end())
#define ers erase
#define ins insert
#define bgn begin
#define clr clear
#define asn assign
#define gln(s) getline(cin,s)
#define rep(i,n) \
  for(int i=0;i<n;++i)
#define repc(i,c,n) \
  for(int i=c;i<n;++i)
#define repr(i,c,n) \
  for(int i=c;i>=n;--i)
#define inf (2147483647/2)
#define pi 3.141592653589793
#define eps 0.00000000001
#define lwb lower_bound

using namespace std;

int main(){
  int n,k;
  ci>>n>>k;
  int b=0,g=0;
  vii res;
  repc(i,1,k)repc(j,1,k){
    int tb=j,tg=j+i;
    if(tg>k) break;
    if(b==tb) swap(tb,tg);
    if(g==tg) swap(tb,tg);
    b=tg;g=tb;
    res.pb(mp(tb,tg));
    res.pb(mp(tg,tb));
    if(res.sz()==n) goto ret;
  }
  ret:
  if(res.sz()==n){
    co<<"YES"<<cl;
    for(auto& p:res)
      co<<p.fs<<" "<<p.sc<<cl;
  }else{
    co<<"NO"<<cl;
  }
  return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <sstream>
#include <cmath>
#include <tuple>
#include <limits>

#define ll long long
#define ull unsigned long long
#define ci cin
#define co cout
#define cl endl
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define mp(i,j) make_pair(i,j)
#define mt(i,j,k) make_tuple(i,j,k)
#define mpq priority_queue<int,vector<int>,greater<int>>
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define vs vector<string>
#define vd vector<double>
#define vii vector<pair<int,int>>
#define vdd vector<pair<double,double>>
#define vvii vector<vector<pair<int,int>>>
#define pb(i) push_back(i)
#define pf(i) push_front(i)
#define ppb() pop_back()
#define ppf() pop_front()
#define sz() size()
#define bk() back()
#define ft() front()
#define fs first
#define sc second
#define max(i,j) ((i>j)?(i):(j))
#define min(i,j) ((i<j)?(i):(j))
#define rvs(i) reverse(i.begin(),i.end())
#define rvsc(i,c) reverse(i.begin(),i.begin()+c)
#define ssort(i) sort(i.begin(),i.end())
#define ers erase
#define ins insert
#define bgn begin
#define clr clear
#define asn assign
#define gln(s) getline(cin,s)
#define rep(i,n) \
  for(int i=0;i<n;++i)
#define repc(i,c,n) \
  for(int i=c;i<n;++i)
#define repr(i,c,n) \
  for(int i=c;i>=n;--i)
#define inf (2147483647/2)
#define pi 3.141592653589793
#define eps 0.00000000001
#define lwb lower_bound

using namespace std;

int main(){
  int n,k;
  ci>>n>>k;
  int b=0,g=0;
  vii res;
  repc(i,1,k)repc(j,1,k){
    int tb=j,tg=j+i;
    if(tg>k) break;
    if(b==tb) swap(tb,tg);
    if(g==tg) swap(tb,tg);
    b=tg;g=tb;
    res.pb(mp(tb,tg));
    res.pb(mp(tg,tb));
    if(res.sz()>n) res.ppb();
    if(res.sz()==n) goto ret;
  }
  ret:
  if(res.sz()==n){
    co<<"YES"<<cl;
    for(auto& p:res)
      co<<p.fs<<" "<<p.sc<<cl;
  }else{
    co<<"NO"<<cl;
  }
  return 0;
}


#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define EPS 1e-6
#define INF 1000000000

// MAXIMIZAR f(x) == MINIMIZAR -f(x)
// It is easy to prove ...

#define _ ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define FORC(i, a, b) for(int i=int(a); i>=int(b); i--)
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << (#x) << " = " << x << "\n";
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

clock_t t_;

using namespace std;

template<class T> void print(T s){cout << s << "\n";}
template<class T> void emax(T &a, T b){a = (a<b ? b : a);};
template<class T> void emin(T &a, T b){a = (a>b ? b : a);}
template<class T> void printC(T s){ for(auto &x : s){cout << x << " ";} cout << "\n";}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define maxn 200005
#define mod 1000000007

int matched[maxn];

int main(int argc, const char * argv[]) {

    #ifdef input
    freopen("input.txt", "r", stdin);
    #endif
    #ifdef output
    freopen("output.txt", "w", stdout);
    #endif
    t_ = clock();

    ll n,k;
    cin >> n >> k;
    if( n > k*k-k){
    	print("NO");
    	return 0;
    }

    FOR(i,0,k+1){
    	matched[i+1] = (i+2)%(k+1);
    }

    int act = 0;
    print("YES");
    while(n--){
    	if(matched[act+1] == act+1){
    		(matched[act+1]+=1)%=(k+1);
    	}
    	cout << act+1 << " " << matched[act+1]+1 << "\n";
    	(act+=1)%=(k+1);
    	(matched[act+1]+=1)%=(k+1);
    }

    t_ = clock()-t_;
    cerr << setprecision(9) << fixed << ((float)t_ / CLOCKS_PER_SEC) << endl;

    return 0;
}


#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define EPS 1e-6
#define INF 1000000000

// MAXIMIZAR f(x) == MINIMIZAR -f(x)
// It is easy to prove ...

#define _ ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define FORC(i, a, b) for(int i=int(a); i>=int(b); i--)
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << (#x) << " = " << x << "\n";
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

clock_t t_;

using namespace std;

template<class T> void print(T s){cout << s << "\n";}
template<class T> void emax(T &a, T b){a = (a<b ? b : a);};
template<class T> void emin(T &a, T b){a = (a>b ? b : a);}
template<class T> void printC(T s){ for(auto &x : s){cout << x << " ";} cout << "\n";}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define maxn 200005
#define mod 1000000007

int matched[maxn];

int main(int argc, const char * argv[]) {

    #ifdef input
    freopen("input.txt", "r", stdin);
    #endif
    #ifdef output
    freopen("output.txt", "w", stdout);
    #endif
    t_ = clock();

    ll n,k;
    cin >> n >> k;
    if( n > k*k-k){
    	print("NO");
    	return 0;
    }

    FOR(i,0,k){
    	matched[i] = (i+1)%k;
    }

    int act = 0;
    print("YES");
    set<ii> helper;
    int prevW = 0;
    while(n--){
    	if((matched[act]) == act){
    		(matched[act]+=1)%=k;
    	}
    	if( matched[act]+1 == prevW){
			(matched[act]+=1)%=k;
    	}
    	while((matched[act]) == act or helper.find({act+1, matched[act]+1}) != helper.end()){
    		(matched[act]+=1)%=k;
    	}
    	cout << act+1 << " " << matched[act]+1 << "\n";
    	prevW = matched[act]+1;
    	helper.insert({act+1, matched[act]+1});
    	act++;
    	act%=k;
    	matched[act]++;
    	matched[act]%=k;
	}

    t_ = clock()-t_;
    cerr << setprecision(9) << fixed << ((float)t_ / CLOCKS_PER_SEC) << endl;

    return 0;
}


#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define EPS 1e-6
#define INF 1000000000

// MAXIMIZAR f(x) == MINIMIZAR -f(x)
// It is easy to prove ...

#define _ ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define FORC(i, a, b) for(int i=int(a); i>=int(b); i--)
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << (#x) << " = " << x << "\n";
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

clock_t t_;

using namespace std;

template<class T> void print(T s){cout << s << "\n";}
template<class T> void emax(T &a, T b){a = (a<b ? b : a);};
template<class T> void emin(T &a, T b){a = (a>b ? b : a);}
template<class T> void printC(T s){ for(auto &x : s){cout << x << " ";} cout << "\n";}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define maxn 200005
#define mod 1000000007

int matched[maxn];

int main(int argc, const char * argv[]) {

    #ifdef input
    freopen("input.txt", "r", stdin);
    #endif
    #ifdef output
    freopen("output.txt", "w", stdout);
    #endif
    t_ = clock();

    ll n,k;
    cin >> n >> k;
    if( n > k*k-k){
    	print("NO");
    	return 0;
    }

    FOR(i,0,k){
    	matched[i] = (i+1)%k;
    }

    int act = 0;
    print("YES");
    set<ii> helper;
    int prevW = 0;
    while(n--){
    	int times = 0;
    	while(times<k && (matched[act]+1 == prevW or (matched[act]) == act or helper.find({act+1, matched[act]+1}) != helper.end())){
    		(matched[act]+=1)%=k;
    		times++;
    	}
    	if(times==k){
    		act++;
    		act%=k;
    		n++;
    		continue;
    	}
    	cout << act+1 << " " << matched[act]+1 << "\n";
    	prevW = matched[act]+1;
    	helper.insert({act+1, matched[act]+1});
    	act++;
    	act%=k;
    	matched[act]++;
    	matched[act]%=k;
	}

    t_ = clock()-t_;
    cerr << setprecision(9) << fixed << ((float)t_ / CLOCKS_PER_SEC) << endl;

    return 0;
}


#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define EPS 1e-6
#define INF 1000000000

// MAXIMIZAR f(x) == MINIMIZAR -f(x)
// It is easy to prove ...

#define _ ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define FORC(i, a, b) for(int i=int(a); i>=int(b); i--)
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << (#x) << " = " << x << "\n";
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

clock_t t_;

using namespace std;

template<class T> void print(T s){cout << s << "\n";}
template<class T> void emax(T &a, T b){a = (a<b ? b : a);};
template<class T> void emin(T &a, T b){a = (a>b ? b : a);}
template<class T> void printC(T s){ for(auto &x : s){cout << x << " ";} cout << "\n";}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define maxn 200005
#define mod 1000000007

int matched[maxn];

int main(int argc, const char * argv[]) {

    #ifdef input
    freopen("input.txt", "r", stdin);
    #endif
    #ifdef output
    freopen("output.txt", "w", stdout);
    #endif
    t_ = clock();

    ll n,k;
    cin >> n >> k;
    if( n > k*k-k){
    	print("NO");
    	return 0;
    }

    FOR(i,0,k){
    	matched[i] = (i+1)%k;
    }

    int act = 0;
    print("YES");
    while(n--){
    	if((matched[act]) == act){
    		(matched[act]+=1)%=k;
    	}
    	cout << act+1 << " " << matched[act]+1 << "\n";
    	act++;
    	act%=k;
    	matched[act]++;
    	matched[act]%=k;
	}

    t_ = clock()-t_;
    cerr << setprecision(9) << fixed << ((float)t_ / CLOCKS_PER_SEC) << endl;

    return 0;
}


#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define EPS 1e-6
#define INF 1000000000

// MAXIMIZAR f(x) == MINIMIZAR -f(x)
// It is easy to prove ...

#define _ ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define FORC(i, a, b) for(int i=int(a); i>=int(b); i--)
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << (#x) << " = " << x << "\n";
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

clock_t t_;

using namespace std;

template<class T> void print(T s){cout << s << "\n";}
template<class T> void emax(T &a, T b){a = (a<b ? b : a);};
template<class T> void emin(T &a, T b){a = (a>b ? b : a);}
template<class T> void printC(T s){ for(auto &x : s){cout << x << " ";} cout << "\n";}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define maxn 200005
#define mod 1000000007

int matched[maxn];

int main(int argc, const char * argv[]) {

    #ifdef input
    freopen("input.txt", "r", stdin);
    #endif
    #ifdef output
    freopen("output.txt", "w", stdout);
    #endif
    t_ = clock();

    ll n,k;
    cin >> n >> k;
    if( n > k*k-k){
    	print("NO");
    	return 0;
    }

    FOR(i,0,k){
    	matched[i] = (i+1)%k;
    }

    int act = 0;
    print("YES");
    set<ii> helper;
    int prevW = 0;
    while(n--){
    	int times = 0;
    	while(times<k && (matched[act]+1 == prevW or (matched[act]) == act or helper.find({act+1, matched[act]+1}) != helper.end())){
    		(matched[act]+=1)%=k;
    		times++;
    	}
    	if(times==k){
    		act++;
    		act%=k;
    		continue;
    	}
    	cout << act+1 << " " << matched[act]+1 << "\n";
    	prevW = matched[act]+1;
    	helper.insert({act+1, matched[act]+1});
    	act++;
    	act%=k;
    	matched[act]++;
    	matched[act]%=k;
	}

    t_ = clock()-t_;
    cerr << setprecision(9) << fixed << ((float)t_ / CLOCKS_PER_SEC) << endl;

    return 0;
}


#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define EPS 1e-6
#define INF 1000000000

// MAXIMIZAR f(x) == MINIMIZAR -f(x)
// It is easy to prove ...

#define _ ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0), cout.precision(15);
#define FOR(i, a, b) for(int i=int(a); i<int(b); i++)
#define FORC(i, a, b) for(int i=int(a); i>=int(b); i--)
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << (#x) << " = " << x << "\n";
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

clock_t t_;

using namespace std;

template<class T> void print(T s){cout << s << "\n";}
template<class T> void emax(T &a, T b){a = (a<b ? b : a);};
template<class T> void emin(T &a, T b){a = (a>b ? b : a);}
template<class T> void printC(T s){ for(auto &x : s){cout << x << " ";} cout << "\n";}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define maxn 200005
#define mod 1000000007

int matched[maxn];

int main(int argc, const char * argv[]) {

    #ifdef input
    freopen("input.txt", "r", stdin);
    #endif
    #ifdef output
    freopen("output.txt", "w", stdout);
    #endif
    t_ = clock();

    ll n,k;
    cin >> n >> k;
    if( n > k*k-k){
    	print("NO");
    	return 0;
    }

    FOR(i,0,k){
    	matched[i] = (i+1)%k;
    }

    int act = 0;
    print("YES");
    set<ii> helper;
    int prevW = 0;
    while(n--){
    	if((matched[act]) == act){
    		(matched[act]+=1)%=k;
    	}
    	if( matched[act]+1 == prevW){
			(matched[act]+=1)%=k;
    	}
    	while(helper.find({act+1, matched[act]+1}) != helper.end()){
    		(matched[act]+=1)%=k;
    	}
    	cout << act+1 << " " << matched[act]+1 << "\n";
    	prevW = matched[act]+1;
    	helper.insert({act+1, matched[act]+1});
    	act++;
    	act%=k;
    	matched[act]++;
    	matched[act]%=k;
	}

    t_ = clock()-t_;
    cerr << setprecision(9) << fixed << ((float)t_ / CLOCKS_PER_SEC) << endl;

    return 0;
}


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

//debugging
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define check(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//normal
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mem(a, b) memset(a, (b), sizeof(a))
#define ch() getchar()
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//#define endl '\n'
#define sz(x) ((int)x.size())

//LOOPS
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define PI 3.1415926535897932384626433832795
const int MOD = 1e9+7;
const ll INF = 1e18;

void solve(){
   int n, k;
   cin>>n>>k;
   int ans = k*(k-1);
   if(ans < n) {
	  cout<<"NO"<<endl;
	  return;
   }
   cout<<"YES"<<endl;
   int p=1, b=0;
   vector<pair<int, int>> v[k];
   FOR(i, 0, k){
	   	FOR(j, 0, k){
			p++;
			debug() << check(i);
			debug() << check(j);
			if(i==j) continue;
			v[i].pb(mp(i+1, p-1));
		}
		p=1;
   }
   FOR(i, 0, k){
	  debug() << check(v[i]);
   }
   p=0;
   FOR(i, 0, k-1){
	   if(b==n) break;
	   debug() << check(b);
	   cout<<v[i][p].first<<" "<<v[i][p].second<<endl;b++;
	   if(b==n) break;
	   cout<<v[i+1][p].first<<" "<<v[i+1][p].second<<endl;b++;
	   FOR(j, p+1, k-1){
		   if(b==n) break;
		   cout<<v[i][j].first<<" "<<v[i][j].second<<endl; b++;
		   if(b==n) break;
		   cout<<v[j+1][i].first<<" "<<v[j+1][i].second<<endl; b++;
	   }p++;
   }
}

int main(){
    fast_io;
    int t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}


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

//debugging
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define check(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//normal
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mem(a, b) memset(a, (b), sizeof(a))
#define ch() getchar()
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//#define endl '\n'
#define sz(x) ((int)x.size())

//LOOPS
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define PI 3.1415926535897932384626433832795
const int MOD = 1e9+7;
const ll INF = 1e18;

void solve(){
   int n, k;
   cin>>n>>k;
   int ans = k*(k-1);
   if(ans < n) {
	  cout<<"NO"<<endl;
	  return;
   }
   cout<<"YES"<<endl;
   int p=1, b=0;
   vector<pair<int, int>> v[k];
   FOR(i, 0, k){
	   	FOR(j, 0, k){
			p++;
			//debug() << check(i);
			//debug() << check(j);
			if(i==j) continue;
			v[i].pb(mp(i+1, p-1));
		}
		p=1;
   }
   //~ FOR(i, 0, k){
	  //~ debug() << check(v[i]);
   //~ }
   p=0;
   FOR(i, 0, k-1){
	   if(b==n) break;
	   b++;
	   cout<<v[i][p].first<<" "<<v[i][p].second
			<<endl<<v[i+1][p].first<<" "<<v[i+1][p].second<<endl;
	   FOR(j, p+1, k-1){
		   cout<<v[i][j].first<<" "<<v[i][j].second
			 <<endl<<v[j+1][i].first<<" "<<v[j+1][i].second<<endl;
		  b+=2;
	   }p++;
   }
}

int main(){
    fast_io;
    int t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}


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

//debugging
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define check(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//normal
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mem(a, b) memset(a, (b), sizeof(a))
#define ch() getchar()
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//#define endl '\n'
#define sz(x) ((int)x.size())

//LOOPS
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define PI 3.1415926535897932384626433832795
const int MOD = 1e9+7;
const ll INF = 1e18;

void solve(){
   int n, k;
   cin>>n>>k;
   int ans = k*(k-1);
   if(ans < n) {
	  cout<<"NO"<<endl;
	  return;
   }
   cout<<"YES"<<endl;
   int p=1, b=0;
   vector<pair<int, int>> v[k];
   FOR(i, 0, k){
	   	FOR(j, 0, k){
			p++;
			debug() << check(i);
			debug() << check(j);
			if(i==j) continue;
			v[i].pb(mp(i+1, p-1));
		}
		p=1;
   }
   //~ FOR(i, 0, k){
	  //~ debug() << check(v[i]);
   //~ }
   p=0;
   FOR(i, 0, k-1){
	   if(b==n) break;
	   b++;
	   cout<<v[i][p].first<<" "<<v[i][p].second
			<<endl<<v[i+1][p].first<<" "<<v[i+1][p].second<<endl;
	   FOR(j, p+1, k-1){
		   cout<<v[i][j].first<<" "<<v[i][j].second
			 <<endl<<v[j+1][i].first<<" "<<v[j+1][i].second<<endl;
		  b+=2;
	   }p++;
   }
}

int main(){
    fast_io;
    int t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}


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

//debugging
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define check(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//normal
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mem(a, b) memset(a, (b), sizeof(a))
#define ch() getchar()
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//#define endl '\n'
#define sz(x) ((int)x.size())

//LOOPS
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define PI 3.1415926535897932384626433832795
const int MOD = 1e9+7;
const ll INF = 1e18;

void solve(){
   int n, k;
   cin>>n>>k;
   ll ans = k*1LL*(k-1);
   debug() << check(ans);
   if(ans < n) {
	  cout<<"NO"<<endl;
	  return;
   }
   cout<<"YES"<<endl;
   int p=0,b=0;
   FOR(i, 0, k-1){
	   if(b==n) break;
	   debug() << check(b);
	   cout<<i+1<<" "<<i+2<<endl;b++;
	   if(b==n) break;
	   cout<<i+2<<" "<<i+1<<endl;b++;
	   FOR(j, p+1, k-1){
		   if(b==n) break;
		   cout<<j+2<<" "<<i+1<<endl; b++;
	   }p++;
   }
}

int main(){
    fast_io;
    int t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}


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

//debugging
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define check(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//normal
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mem(a, b) memset(a, (b), sizeof(a))
#define ch() getchar()
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//#define endl '\n'
#define sz(x) ((int)x.size())

//LOOPS
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define PI 3.1415926535897932384626433832795
const int MOD = 1e9+7;
const ll INF = 1e18;

void solve(){
   int n, k;
   cin>>n>>k;
   ll ans = k*1LL*(k-1);
   debug() << check(ans);
   if(ans < n) {
	  cout<<"NO"<<endl;
	  return;
   }
   cout<<"YES"<<endl;
   int p=0,b=0;
   FOR(i, 0, k-1){
	   if(b==n) break;
	   debug() << check(b);
	   cout<<i+1<<" "<<i+2<<endl;b++;
	   if(b==n) break;
	   cout<<i+2<<" "<<i+1<<endl;b++;
	   FOR(j, p+1, k-1){a
		   if(b==n) break;
		   cout<<j+2<<" "<<i+1<<endl; b++;
	   }p++;
   }
}

int main(){
    fast_io;
    int t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}


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

//debugging
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define check(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//normal
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mem(a, b) memset(a, (b), sizeof(a))
#define ch() getchar()
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//#define endl '\n'
#define sz(x) ((int)x.size())

//LOOPS
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define PI 3.1415926535897932384626433832795
const int MOD = 1e9+7;
const ll INF = 1e18;

void solve(){
   int n, k;
   cin>>n>>k;
   int ans = k*(k-1);
   if(ans < n) {
	  cout<<"NO"<<endl;
	  return;
   }
   cout<<"YES"<<endl;
   int p=1, b=0;
   vector<pair<int, int>> v[k];
   FOR(i, 0, k){
	   	FOR(j, 0, k){
			p++;
			debug() << check(i);
			debug() << check(j);
			if(i==j) continue;
			v[i].pb(mp(i+1, p-1));
		}
		p=1;
   }
   FOR(i, 0, k){
	  debug() << check(v[i]);
   }
   p=0;
   FOR(i, 0, k-1){
	   if(b==n) break;
	   b++;
	   cout<<v[i][p].first<<" "<<v[i][p].second
			<<endl<<v[i+1][p].first<<" "<<v[i+1][p].second<<endl;
	   FOR(j, p+1, k-1){
		   cout<<v[i][j].first<<" "<<v[i][j].second
			 <<endl<<v[j+1][i].first<<" "<<v[j+1][i].second<<endl;
		  b+=2;
	   }p++;
   }
}

int main(){
    fast_io;
    int t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}


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

//debugging
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define check(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//normal
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mem(a, b) memset(a, (b), sizeof(a))
#define ch() getchar()
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//#define endl '\n'
#define sz(x) ((int)x.size())

//LOOPS
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define PI 3.1415926535897932384626433832795
const int MOD = 1e9+7;
const ll INF = 1e18;

void solve(){
   int n, k;
   cin>>n>>k;
   int ans = k*(k-1);
   if(ans < n) {
	  cout<<"NO"<<endl;
	  return;
   }
   cout<<"YES"<<endl;
   int p=0,b=0;
   FOR(i, 0, k-1){
	   if(b==n) break;
	   debug() << check(b);
	   cout<<i+1<<" "<<i+2<<endl;b++;
	   if(b==n) break;
	   cout<<i+2<<" "<<i+1<<endl;b++;
	   FOR(j, p+1, k-1){
		   if(b==n) break;
		   cout<<i+1<<" "<<j+2<<endl; b++;
		   if(b==n) break;
		   cout<<j+2<<" "<<i+1<<endl; b++;
	   }p++;
   }
}

int main(){
    fast_io;
    int t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}


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

//debugging
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define check(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

//normal
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mem(a, b) memset(a, (b), sizeof(a))
#define ch() getchar()
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//#define endl '\n'
#define sz(x) ((int)x.size())

//LOOPS
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define PI 3.1415926535897932384626433832795
const int MOD = 1e9+7;
const ll INF = 1e18;

void solve(){
   int n, k;
   cin>>n>>k;
   ll ans = k*1ll*(k-1);
   if(ans < n) {
	  cout<<"NO"<<endl;
	  return;
   }
   cout<<"YES"<<endl;
   int p=0,b=0;
   FOR(i, 0, k-1){
	   if(b==n) break;
	   debug() << check(b);
	   cout<<i+1<<" "<<i+2<<endl;b++;
	   if(b==n) break;
	   cout<<i+2<<" "<<i+1<<endl;b++;
	   FOR(j, p+1, k-1){
		   if(b==n) break;
		   cout<<i+1<<" "<<j+2<<endl; b++;
		   if(b==n) break;
		   cout<<j+2<<" "<<i+1<<endl; b++;
	   }p++;
   }
}

int main(){
    fast_io;
    int t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 1000000007
using namespace __gnu_pbds;
typedef int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

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

ll t=1;
//cin>>t;
while(t--)
{

ll n,k;
cin>>n>>k;

if(n>(k*k)-k)
cout<<"NO"<<endl;
else
{
cout<<"YeS"<<endl;
ll m=(2*k)-2;
ll j=0,i;
ll u=1;
ll v=k-1;
vector<ll>l,r;

while(m--)
{
if(j%2==0){
ll te=1;
for(i=u;i<k;i++)
{
l.push_back(te);
r.push_back(i+1);
te++;
}
u++;

}
else
{
    ll te=k;
for(ll i=v;i>=1;i--){
l.push_back(te);
r.push_back(i);
te--;
}
v--;
}
if(l.size()>500009)
    break;
j++;
}

for(i=0;i<n;i++)
cout<<l[i]<<" "<<r[i]<<endl;

}

}
return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 1000000007
using namespace __gnu_pbds;
typedef int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

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

ll t=1;
//cin>>t;
while(t--)
{

ll n,k;
cin>>n>>k;

if(n>(k*k)-k)
cout<<"NO"<<endl;
else
{
cout<<"YeS"<<endl;
ll m=(2*k)-2;
ll j=0,i;
ll u=1;
ll v=k-1;
vector<ll>l,r;

while(m--)
{
if(j%2==0){
ll te=1;
for(i=u;i<k;i++)
{
l.push_back(te);
r.push_back(i+1);
te++;
}
u++;

}
else
{
    ll te=k;
for(ll i=v;i>=1;i--){
l.push_back(te);
r.push_back(i);
te--;
}
v--;
}

j++;
}

for(i=0;i<n;i++)
cout<<l[i]<<" "<<r[i]<<endl;

}

}
return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 1000000007
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

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

ll t=1;
//cin>>t;
while(t--)
{

ll n,k;
cin>>n>>k;

if(n>(k*k)-k)
cout<<"NO"<<endl;
else
{
cout<<"YeS"<<endl;
ll m=(2*k)-2;
ll j=0,i;
ll u=1;
ll v=k-1;
vector<ll>l,r;

while(m--)
{
if(j%2==0)
for(i=u;i<k;i++){
{
l.push_back(i);
r.push_back(i+1);
}
u++;
}
else
{
for(ll i=v;i>=1;i--){
l.push_back(i+1);
r.push_back(i);
}
v--;
}
if(l.size()>300009)
    break;
j++;
}

for(i=0;i<n;i++)
cout<<l[i]<<" "<<r[i]<<endl;

}

}
return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 1000000007
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

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

ll t=1;
//cin>>t;
while(t--)
{

ll n,k;
cin>>n>>k;

if(n>(k*k)-k)
cout<<"NO"<<endl;
else
{
cout<<"YeS"<<endl;
ll m=(2*k)-2;
ll j=0,i;
ll u=1;
ll v=k-1;
vector<ll>l,r;

while(m--)
{
if(j%2==0){
ll te=1;
for(i=u;i<k;i++)
{
l.push_back(te);
r.push_back(i+1);
te++;
}
u++;

}
else
{
    ll te=k;
for(ll i=v;i>=1;i--){
l.push_back(te);
r.push_back(i);
te--;
}
v--;
}

j++;
}

for(i=0;i<n;i++)
cout<<l[i]<<" "<<r[i]<<endl;

}

}
return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 1000000007
using namespace __gnu_pbds;
typedef int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

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

ll t=1;
//cin>>t;
while(t--)
{

ll n,k;
cin>>n>>k;

if(n>(k*k)-k)
cout<<"NO"<<endl;
else
{
cout<<"YeS"<<endl;
ll m=(2*k)-2;
ll j=0,i;
ll u=1;
ll v=k-1;
vector<ll>l,r;

while(m--)
{
if(j%2==0){
ll te=1;
for(i=u;i<k;i++)
{
l.push_back(te);
r.push_back(i+1);
te++;
}
u++;

}
else
{
    ll te=k;
for(ll i=v;i>=1;i--){
l.push_back(te);
r.push_back(i);
te--;
}
v--;
}
if(l.size()>300009)
    break;
j++;
}

for(i=0;i<n;i++)
cout<<l[i]<<" "<<r[i]<<endl;

}

}
return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 1000000007
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

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

ll t=1;
//cin>>t;
while(t--)
{

ll n,k;
cin>>n>>k;

if(n>(k*k)-k)
cout<<"NO"<<endl;
else
{
cout<<"YeS"<<endl;
ll m=k-1;
ll j=0,i;
ll u=1;
ll v=k-1;
vector<ll>l,r;

while(m--)
{
if(j%2==0)
{
for(i=u;i<k;i++){
l.push_back(i);
r.push_back(i+1);
}
u++;
}
else
{
for(ll i=v;i>=1;i--){
l.push_back(i+1);
r.push_back(i);
}
v--;
}
j++;
}

for(i=0;i<n;i++)
cout<<l[i]<<" "<<r[i]<<endl;

}

}
return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 1000000007
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

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

ll t=1;
//cin>>t;
while(t--)
{

ll n,k;
cin>>n>>k;

if(n>(k*k)-k)
cout<<"NO"<<endl;
else
{
cout<<"YeS"<<endl;
ll m=(2*k)-2;
ll j=0,i;
ll u=1;
ll v=k-1;
vector<ll>l,r;

while(m--)
{
if(j%2==0){
ll te=1;
for(i=u;i<k;i++)
{
l.push_back(te);
r.push_back(i+1);
te++;
}
u++;

}
else
{
    ll te=k;
for(ll i=v;i>=1;i--){
l.push_back(te);
r.push_back(i);
te--;
}
v--;
}
if(l.size()>500009)
    break;
j++;
}

for(i=0;i<n;i++)
cout<<l[i]<<" "<<r[i]<<endl;

}

}
return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 1000000007
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

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

ll t=1;
//cin>>t;
while(t--)
{

ll n,k;
cin>>n>>k;

if(n>(k*k)-k)
cout<<"NO"<<endl;
else
{
cout<<"YeS"<<endl;
ll m=(2*k)-2;
ll j=0,i;
ll u=1;
ll v=k-1;
vector<ll>l,r;

while(m--)
{
if(j%2==0)
{
for(i=u;i<k;i++){
l.push_back(i);
r.push_back(i+1);
}
u++;
}
else
{
for(ll i=v;i>=1;i--){
l.push_back(i+1);
r.push_back(i);
}
v--;
}
if(l.size()>300009)

j++;
}
cout<<l.size()<<endl;
for(i=0;i<n;i++)
cout<<l[i]<<" "<<r[i]<<endl;

}

}
return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod 1000000007
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

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

ll t=1;
//cin>>t;
while(t--)
{

ll n,k;
cin>>n>>k;

if(n>(k*k)-k)
cout<<"NO"<<endl;
else
{
cout<<"YeS"<<endl;
ll m=n-1;
ll j=0,i;
ll u=1;
ll v=n-1;
vector<ll>l,r;

while(m--)
{
if(j%2==0)
{
for(i=u;i<n;i++){
l.push_back(i);
r.push_back(i+1);
}
u++;
}
else
{
for(ll i=v;i>=1;i--){
l.push_back(i+1);
r.push_back(i);
}
v--;
}
j++;
}

for(i=0;i<n;i++)
cout<<l[i]<<" "<<r[i]<<endl;

}

}
return 0;
}


//#pragma GCC optimize ("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using ld = long double;
using itn = int;
mt19937 gen(41);
const ll INF = 1e9 + 7;
const ll num_mod = 1e9 + 7;
#define endl "\n"

struct number {
	ll x;
	number(ll X) {
		x = X;
	}
	void print() {
		cout << x % num_mod;
		cout << " ";
		cout << endl;
	}
	number operator+= (number &a) {
		x = (x + a.x) % num_mod;
		return *this;
	}
	friend number operator+ (number &a, number &b) {
		number c = a;
		return c += b;
	}
	number operator-= (number &a) {
		x = (x - a.x + num_mod) % num_mod;
		return *this;
	}
	friend number operator- (number &a, number &b) {
		number c = a;
		return c -= b;
	}
	number operator*= (number &a) {
		x = (x * a.x) % num_mod;
		return *this;
	}
	friend number operator* (number &a, number &b) {
		number c = a;
		return c *= b;
	}
};

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

vector<int> parent;
vector<int> Rank;
stack<pair<bool, pair<int, int> > > st;

void make_set(int v) {
	parent[v] = v;
	Rank[v] = 1;
}

void resize_set(int n) {
	parent.resize(n);
	Rank.resize(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (Rank[a] < Rank[b])
			swap(a, b);
		parent[b] = a;
		bool f = false;
		if (Rank[a] == Rank[b]) {
			++Rank[a];
			f = true;
		}
		//st.push({ f, { a, b } });
	}
	else {
		//st.push({ false, { -1, -1 } });
	}
}

void undo() {
	assert(!st.empty());
	if (st.top().second.first == -1) {
		st.pop();
		return;
	}
	int a = st.top().second.first;
	int b = st.top().second.second;
	parent[b] = b;
	if (st.top().first) Rank[a]--;
	st.pop();
}

void no() {
	cout << "NO";
	exit(0);
}
void yes() {
	cout << "YES";
	exit(0);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif // DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------------------
	ll n, k;
	cin >> n >> k;
	int N = n;
	if (k * k - k < n) {
		cout << "NO";
		return 0;
	}
	vector<pair<int, int> > res;
	for (int i = 1; i <= k; i++) {
		for (int j = i + 1; j <= k; j++) {
			if (N) {
				res.push_back({ i, j });
				N--;
			}
			if (N) {
				res.push_back({ j, i });
				N--;
			}
			else {
				break;
			}
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}
	//------------------------------------------------
	return 0;
}


//#pragma GCC optimize ("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using ld = long double;
using itn = int;
mt19937 gen(41);
const ll INF = 1e9 + 7;
const ll num_mod = 1e9 + 7;
#define endl "\n"

struct number {
	ll x;
	number(ll X) {
		x = X;
	}
	void print() {
		cout << x % num_mod;
		cout << " ";
		cout << endl;
	}
	number operator+= (number &a) {
		x = (x + a.x) % num_mod;
		return *this;
	}
	friend number operator+ (number &a, number &b) {
		number c = a;
		return c += b;
	}
	number operator-= (number &a) {
		x = (x - a.x + num_mod) % num_mod;
		return *this;
	}
	friend number operator- (number &a, number &b) {
		number c = a;
		return c -= b;
	}
	number operator*= (number &a) {
		x = (x * a.x) % num_mod;
		return *this;
	}
	friend number operator* (number &a, number &b) {
		number c = a;
		return c *= b;
	}
};

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

vector<int> parent;
vector<int> Rank;
stack<pair<bool, pair<int, int> > > st;

void make_set(int v) {
	parent[v] = v;
	Rank[v] = 1;
}

void resize_set(int n) {
	parent.resize(n);
	Rank.resize(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (Rank[a] < Rank[b])
			swap(a, b);
		parent[b] = a;
		bool f = false;
		if (Rank[a] == Rank[b]) {
			++Rank[a];
			f = true;
		}
		//st.push({ f, { a, b } });
	}
	else {
		//st.push({ false, { -1, -1 } });
	}
}

void undo() {
	assert(!st.empty());
	if (st.top().second.first == -1) {
		st.pop();
		return;
	}
	int a = st.top().second.first;
	int b = st.top().second.second;
	parent[b] = b;
	if (st.top().first) Rank[a]--;
	st.pop();
}

void no() {
	cout << "NO";
	exit(0);
}
void yes() {
	cout << "YES";
	exit(0);
}

bool check(const string &s) {
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i]) return false;
	}
	return true;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif // DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------------------
	int n, k;
	cin >> n >> k;
	queue<pair<int, int> > p;
	for (int i = 1; i <= min((int)sqrt(n) + 3, k); i++) {
		for (int j = 1; j <= min((int)sqrt(n) + 3, k); j++) {
			if (i == j) continue;
			p.push({ i, j });
		}
	}
	if (p.size() < n) {
		cout << "NO";
		return 0;
	}
	vector<pair<int, int> > res;
	res.push_back(p.front());
	p.pop();
	while (res.size() < n) {
		pair<int, int> k = p.front();
		p.pop();
		if (res.back().first == k.first || res.back().second == k.second)
			p.push(k);
		else
			res.push_back(k);
	}
	cout << "YES\n";
	for (int i = 0; i < n; i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}
	//------------------------------------------------
	return 0;
}


//#pragma GCC optimize ("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using ld = long double;
using itn = int;
mt19937 gen(41);
const ll INF = 1e9 + 7;
const ll num_mod = 1e9 + 7;
#define endl "\n"

struct number {
	ll x;
	number(ll X) {
		x = X;
	}
	void print() {
		cout << x % num_mod;
		cout << " ";
		cout << endl;
	}
	number operator+= (number &a) {
		x = (x + a.x) % num_mod;
		return *this;
	}
	friend number operator+ (number &a, number &b) {
		number c = a;
		return c += b;
	}
	number operator-= (number &a) {
		x = (x - a.x + num_mod) % num_mod;
		return *this;
	}
	friend number operator- (number &a, number &b) {
		number c = a;
		return c -= b;
	}
	number operator*= (number &a) {
		x = (x * a.x) % num_mod;
		return *this;
	}
	friend number operator* (number &a, number &b) {
		number c = a;
		return c *= b;
	}
};

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

vector<int> parent;
vector<int> Rank;
stack<pair<bool, pair<int, int> > > st;

void make_set(int v) {
	parent[v] = v;
	Rank[v] = 1;
}

void resize_set(int n) {
	parent.resize(n);
	Rank.resize(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (Rank[a] < Rank[b])
			swap(a, b);
		parent[b] = a;
		bool f = false;
		if (Rank[a] == Rank[b]) {
			++Rank[a];
			f = true;
		}
		//st.push({ f, { a, b } });
	}
	else {
		//st.push({ false, { -1, -1 } });
	}
}

void undo() {
	assert(!st.empty());
	if (st.top().second.first == -1) {
		st.pop();
		return;
	}
	int a = st.top().second.first;
	int b = st.top().second.second;
	parent[b] = b;
	if (st.top().first) Rank[a]--;
	st.pop();
}

void no() {
	cout << "NO";
	exit(0);
}
void yes() {
	cout << "YES";
	exit(0);
}

bool check(const string &s) {
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i]) return false;
	}
	return true;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif // DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------------------
	int n, k;
	cin >> n >> k;
	if (k * k - k < n) {
		cout << "NO";
		return 0;
	}
	deque<pair<int, int> > p;
	for (int i = 1; i <= min((int)sqrt(n) + 3, k); i++) {
		for (int j = 1; j <= min((int)sqrt(n) + 3, k); j++) {
			if (i == j) continue;
			p.push_back({ i, j });
		}
	}
	if (p.size() < n) {
		cout << "NO";
		return 0;
	}
	random_shuffle(p.begin(), p.end());
	vector<pair<int, int> > res;
	res.push_back(p.front());
	p.pop_front();
	while (res.size() < n) {
		pair<int, int> k = p.front();
		p.pop_front();
		if (res.back().first == k.first || res.back().second == k.second) {
			p.push_back(k);
		}
		else {
			res.push_back(k);
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}
	//------------------------------------------------
	return 0;
}


//#pragma GCC optimize ("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using ld = long double;
using itn = int;
mt19937 gen(41);
const ll INF = 1e9 + 7;
const ll num_mod = 1e9 + 7;
#define endl "\n"

struct number {
	ll x;
	number(ll X) {
		x = X;
	}
	void print() {
		cout << x % num_mod;
		cout << " ";
		cout << endl;
	}
	number operator+= (number &a) {
		x = (x + a.x) % num_mod;
		return *this;
	}
	friend number operator+ (number &a, number &b) {
		number c = a;
		return c += b;
	}
	number operator-= (number &a) {
		x = (x - a.x + num_mod) % num_mod;
		return *this;
	}
	friend number operator- (number &a, number &b) {
		number c = a;
		return c -= b;
	}
	number operator*= (number &a) {
		x = (x * a.x) % num_mod;
		return *this;
	}
	friend number operator* (number &a, number &b) {
		number c = a;
		return c *= b;
	}
};

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

vector<int> parent;
vector<int> Rank;
stack<pair<bool, pair<int, int> > > st;

void make_set(int v) {
	parent[v] = v;
	Rank[v] = 1;
}

void resize_set(int n) {
	parent.resize(n);
	Rank.resize(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (Rank[a] < Rank[b])
			swap(a, b);
		parent[b] = a;
		bool f = false;
		if (Rank[a] == Rank[b]) {
			++Rank[a];
			f = true;
		}
		//st.push({ f, { a, b } });
	}
	else {
		//st.push({ false, { -1, -1 } });
	}
}

void undo() {
	assert(!st.empty());
	if (st.top().second.first == -1) {
		st.pop();
		return;
	}
	int a = st.top().second.first;
	int b = st.top().second.second;
	parent[b] = b;
	if (st.top().first) Rank[a]--;
	st.pop();
}

void no() {
	cout << "NO";
	exit(0);
}
void yes() {
	cout << "YES";
	exit(0);
}

bool check(const string &s) {
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i]) return false;
	}
	return true;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif // DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------------------
	int n, k;
	cin >> n >> k;
	if (k * k - k < n) {
		cout << "NO";
		return 0;
	}
	deque<pair<int, int> > p;
	for (int i = 1; i <= min((int)sqrt(n) + 3, k); i++) {
		for (int j = 1; j <= min((int)sqrt(n) + 3, k); j++) {
			if (i == j) continue;
			p.push_back({ i, j });
		}
	}
	if (p.size() < n) {
		cout << "NO";
		return 0;
	}
	random_shuffle(p.begin(), p.end());
	vector<pair<int, int> > res;
	res.push_back(p.front());
	p.pop_back();
	while (res.size() < n) {
		pair<int, int> k = p.front();
		p.pop_front();
		if (res.back().first == k.first || res.back().second == k.second) {
			p.push_back(k);
		}
		else {
			res.push_back(k);
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}
	//------------------------------------------------
	return 0;
}


//#pragma GCC optimize ("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using ld = long double;
using itn = int;
mt19937 gen(41);
const ll INF = 1e9 + 7;
const ll num_mod = 1e9 + 7;
#define endl "\n"

struct number {
	ll x;
	number(ll X) {
		x = X;
	}
	void print() {
		cout << x % num_mod;
		cout << " ";
		cout << endl;
	}
	number operator+= (number &a) {
		x = (x + a.x) % num_mod;
		return *this;
	}
	friend number operator+ (number &a, number &b) {
		number c = a;
		return c += b;
	}
	number operator-= (number &a) {
		x = (x - a.x + num_mod) % num_mod;
		return *this;
	}
	friend number operator- (number &a, number &b) {
		number c = a;
		return c -= b;
	}
	number operator*= (number &a) {
		x = (x * a.x) % num_mod;
		return *this;
	}
	friend number operator* (number &a, number &b) {
		number c = a;
		return c *= b;
	}
};

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

vector<int> parent;
vector<int> Rank;
stack<pair<bool, pair<int, int> > > st;

void make_set(int v) {
	parent[v] = v;
	Rank[v] = 1;
}

void resize_set(int n) {
	parent.resize(n);
	Rank.resize(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (Rank[a] < Rank[b])
			swap(a, b);
		parent[b] = a;
		bool f = false;
		if (Rank[a] == Rank[b]) {
			++Rank[a];
			f = true;
		}
		//st.push({ f, { a, b } });
	}
	else {
		//st.push({ false, { -1, -1 } });
	}
}

void undo() {
	assert(!st.empty());
	if (st.top().second.first == -1) {
		st.pop();
		return;
	}
	int a = st.top().second.first;
	int b = st.top().second.second;
	parent[b] = b;
	if (st.top().first) Rank[a]--;
	st.pop();
}

void no() {
	cout << "NO";
	exit(0);
}
void yes() {
	cout << "YES";
	exit(0);
}

bool check(const string &s) {
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i]) return false;
	}
	return true;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif // DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------------------
	int n, k;
	cin >> n >> k;
	if (k * k - k < n) {
		cout << "NO";
		return 0;
	}
	deque<pair<int, int> > p;
	for (int i = 1; i <= min((int)sqrt(n) + 3, k); i++) {
		for (int j = 1; j <= min((int)sqrt(n) + 3, k); j++) {
			if (i == j) continue;
			p.push_back({ i, j });
		}
	}
	if (p.size() < n) {
		cout << "NO";
		return 0;
	}
	shuffle(p.begin(), p.end(), gen());
	vector<pair<int, int> > res;
	res.push_back(p.front());
	p.pop_front();
	while (res.size() < n) {
		pair<int, int> k = p.front();
		p.pop_front();
		if (res.back().first == k.first || res.back().second == k.second) {
			p.push_back(k);
		}
		else {
			res.push_back(k);
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}
	//------------------------------------------------
	return 0;
}


//#pragma GCC optimize ("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using ld = long double;
using itn = int;
mt19937 gen(41);
const ll INF = 1e9 + 7;
const ll num_mod = 1e9 + 7;
#define endl "\n"

struct number {
	ll x;
	number(ll X) {
		x = X;
	}
	void print() {
		cout << x % num_mod;
		cout << " ";
		cout << endl;
	}
	number operator+= (number &a) {
		x = (x + a.x) % num_mod;
		return *this;
	}
	friend number operator+ (number &a, number &b) {
		number c = a;
		return c += b;
	}
	number operator-= (number &a) {
		x = (x - a.x + num_mod) % num_mod;
		return *this;
	}
	friend number operator- (number &a, number &b) {
		number c = a;
		return c -= b;
	}
	number operator*= (number &a) {
		x = (x * a.x) % num_mod;
		return *this;
	}
	friend number operator* (number &a, number &b) {
		number c = a;
		return c *= b;
	}
};

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

vector<int> parent;
vector<int> Rank;
stack<pair<bool, pair<int, int> > > st;

void make_set(int v) {
	parent[v] = v;
	Rank[v] = 1;
}

void resize_set(int n) {
	parent.resize(n);
	Rank.resize(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (Rank[a] < Rank[b])
			swap(a, b);
		parent[b] = a;
		bool f = false;
		if (Rank[a] == Rank[b]) {
			++Rank[a];
			f = true;
		}
		//st.push({ f, { a, b } });
	}
	else {
		//st.push({ false, { -1, -1 } });
	}
}

void undo() {
	assert(!st.empty());
	if (st.top().second.first == -1) {
		st.pop();
		return;
	}
	int a = st.top().second.first;
	int b = st.top().second.second;
	parent[b] = b;
	if (st.top().first) Rank[a]--;
	st.pop();
}

void no() {
	cout << "NO";
	exit(0);
}
void yes() {
	cout << "YES";
	exit(0);
}

bool check(const string &s) {
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i]) return false;
	}
	return true;
}

int myrandom(int i) { return gen() % i; }

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif // DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------------------
	ll n, k;
	cin >> n >> k;
	if (k * k - k < n) {
		cout << "NO";
		return 0;
	}
	deque<pair<ll, ll> > p;
	for (ll i = 1; i <= min((ll)sqrt(n) + 3, k); i++) {
		for (ll j = 1; j <= min((ll)sqrt(n) + 3, k); j++) {
			if (i == j) continue;
			p.push_back({ i, j });
		}
	}
	if (p.size() < n) {
		cout << "NO";
		return 0;
	}
	random_shuffle(p.begin(), p.end(), myrandom);
	vector<pair<ll, ll> > res;
	res.push_back(p.front());
	p.pop_front();
	while (res.size() < n) {
		pair<ll, ll> k = p.front();
		p.pop_front();
		if (res.back().first == k.first || res.back().second == k.second) {
			p.push_back(k);
		}
		else {
			res.push_back(k);
		}
	}
	cout << "YES\n";
	for (ll i = 0; i < n; i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}
	//------------------------------------------------
	return 0;
}


//#pragma GCC optimize ("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using ld = long double;
using itn = int;
mt19937 gen(41);
const ll INF = 1e9 + 7;
const ll num_mod = 1e9 + 7;
#define endl "\n"

struct number {
	ll x;
	number(ll X) {
		x = X;
	}
	void print() {
		cout << x % num_mod;
		cout << " ";
		cout << endl;
	}
	number operator+= (number &a) {
		x = (x + a.x) % num_mod;
		return *this;
	}
	friend number operator+ (number &a, number &b) {
		number c = a;
		return c += b;
	}
	number operator-= (number &a) {
		x = (x - a.x + num_mod) % num_mod;
		return *this;
	}
	friend number operator- (number &a, number &b) {
		number c = a;
		return c -= b;
	}
	number operator*= (number &a) {
		x = (x * a.x) % num_mod;
		return *this;
	}
	friend number operator* (number &a, number &b) {
		number c = a;
		return c *= b;
	}
};

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

vector<int> parent;
vector<int> Rank;
stack<pair<bool, pair<int, int> > > st;

void make_set(int v) {
	parent[v] = v;
	Rank[v] = 1;
}

void resize_set(int n) {
	parent.resize(n);
	Rank.resize(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (Rank[a] < Rank[b])
			swap(a, b);
		parent[b] = a;
		bool f = false;
		if (Rank[a] == Rank[b]) {
			++Rank[a];
			f = true;
		}
		//st.push({ f, { a, b } });
	}
	else {
		//st.push({ false, { -1, -1 } });
	}
}

void undo() {
	assert(!st.empty());
	if (st.top().second.first == -1) {
		st.pop();
		return;
	}
	int a = st.top().second.first;
	int b = st.top().second.second;
	parent[b] = b;
	if (st.top().first) Rank[a]--;
	st.pop();
}

void no() {
	cout << "NO";
	exit(0);
}
void yes() {
	cout << "YES";
	exit(0);
}

bool check(const string &s) {
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i]) return false;
	}
	return true;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif // DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------------------
	int n, k;
	cin >> n >> k;
	if (k * k - k < n) {
		cout << "NO";
		return 0;
	}
	deque<pair<int, int> > p;
	for (int i = 1; i <= min((int)sqrt(n) + 3, k); i++) {
		for (int j = 1; j <= min((int)sqrt(n) + 3, k); j++) {
			if (i == j) continue;
			p.push_back({ i, j });
		}
	}
	if (p.size() < n) {
		cout << "NO";
		return 0;
	}
	shuffle(p.begin(), p.end(), gen);
	vector<pair<int, int> > res;
	res.push_back(p.front());
	p.pop_front();
	while (res.size() < n) {
		pair<int, int> k = p.front();
		p.pop_front();
		if (res.back().first == k.first || res.back().second == k.second) {
			p.push_back(k);
		}
		else {
			res.push_back(k);
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}
	//------------------------------------------------
	return 0;
}


//#pragma GCC optimize ("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using ld = long double;
using itn = int;
mt19937 gen(41);
const ll INF = 1e9 + 7;
const ll num_mod = 1e9 + 7;
#define endl "\n"

struct number {
	ll x;
	number(ll X) {
		x = X;
	}
	void print() {
		cout << x % num_mod;
		cout << " ";
		cout << endl;
	}
	number operator+= (number &a) {
		x = (x + a.x) % num_mod;
		return *this;
	}
	friend number operator+ (number &a, number &b) {
		number c = a;
		return c += b;
	}
	number operator-= (number &a) {
		x = (x - a.x + num_mod) % num_mod;
		return *this;
	}
	friend number operator- (number &a, number &b) {
		number c = a;
		return c -= b;
	}
	number operator*= (number &a) {
		x = (x * a.x) % num_mod;
		return *this;
	}
	friend number operator* (number &a, number &b) {
		number c = a;
		return c *= b;
	}
};

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

vector<int> parent;
vector<int> Rank;
stack<pair<bool, pair<int, int> > > st;

void make_set(int v) {
	parent[v] = v;
	Rank[v] = 1;
}

void resize_set(int n) {
	parent.resize(n);
	Rank.resize(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (Rank[a] < Rank[b])
			swap(a, b);
		parent[b] = a;
		bool f = false;
		if (Rank[a] == Rank[b]) {
			++Rank[a];
			f = true;
		}
		//st.push({ f, { a, b } });
	}
	else {
		//st.push({ false, { -1, -1 } });
	}
}

void undo() {
	assert(!st.empty());
	if (st.top().second.first == -1) {
		st.pop();
		return;
	}
	int a = st.top().second.first;
	int b = st.top().second.second;
	parent[b] = b;
	if (st.top().first) Rank[a]--;
	st.pop();
}

void no() {
	cout << "NO";
	exit(0);
}
void yes() {
	cout << "YES";
	exit(0);
}

bool check(const string &s) {
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i]) return false;
	}
	return true;
}

int myrandom(int i) { return gen() % i; }

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif // DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------------------
	int n, k;
	cin >> n >> k;
	if (k * k - k < n) {
		cout << "NO";
		return 0;
	}
	deque<pair<int, int> > p;
	for (int i = 1; i <= min((int)sqrt(n) + 3, k); i++) {
		for (int j = 1; j <= min((int)sqrt(n) + 3, k); j++) {
			if (i == j) continue;
			p.push_back({ i, j });
		}
	}
	if (p.size() < n) {
		cout << "NO";
		return 0;
	}
	random_shuffle(p.begin(), p.end(), myrandom);
	vector<pair<int, int> > res;
	res.push_back(p.front());
	p.pop_front();
	while (res.size() < n) {
		pair<int, int> k = p.front();
		p.pop_front();
		if (res.back().first == k.first || res.back().second == k.second) {
			p.push_back(k);
		}
		else {
			res.push_back(k);
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}
	//------------------------------------------------
	return 0;
}


//#pragma GCC optimize ("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using ld = long double;
using itn = int;
mt19937 gen(41);
const ll INF = 1e9 + 7;
const ll num_mod = 1e9 + 7;
#define endl "\n"

struct number {
	ll x;
	number(ll X) {
		x = X;
	}
	void print() {
		cout << x % num_mod;
		cout << " ";
		cout << endl;
	}
	number operator+= (number &a) {
		x = (x + a.x) % num_mod;
		return *this;
	}
	friend number operator+ (number &a, number &b) {
		number c = a;
		return c += b;
	}
	number operator-= (number &a) {
		x = (x - a.x + num_mod) % num_mod;
		return *this;
	}
	friend number operator- (number &a, number &b) {
		number c = a;
		return c -= b;
	}
	number operator*= (number &a) {
		x = (x * a.x) % num_mod;
		return *this;
	}
	friend number operator* (number &a, number &b) {
		number c = a;
		return c *= b;
	}
};

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

vector<int> parent;
vector<int> Rank;
stack<pair<bool, pair<int, int> > > st;

void make_set(int v) {
	parent[v] = v;
	Rank[v] = 1;
}

void resize_set(int n) {
	parent.resize(n);
	Rank.resize(n);
	for (int i = 0; i < n; i++) {
		make_set(i);
	}
}

int find_set(int v) {
	if (v == parent[v])
		return v;
	return find_set(parent[v]);
}

void union_sets(int a, int b) {
	a = find_set(a);
	b = find_set(b);
	if (a != b) {
		if (Rank[a] < Rank[b])
			swap(a, b);
		parent[b] = a;
		bool f = false;
		if (Rank[a] == Rank[b]) {
			++Rank[a];
			f = true;
		}
		//st.push({ f, { a, b } });
	}
	else {
		//st.push({ false, { -1, -1 } });
	}
}

void undo() {
	assert(!st.empty());
	if (st.top().second.first == -1) {
		st.pop();
		return;
	}
	int a = st.top().second.first;
	int b = st.top().second.second;
	parent[b] = b;
	if (st.top().first) Rank[a]--;
	st.pop();
}

void no() {
	cout << "NO";
	exit(0);
}
void yes() {
	cout << "YES";
	exit(0);
}

bool check(const string &s) {
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - 1 - i]) return false;
	}
	return true;
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
#endif // DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//----------------------------------------------------------
	int n, k;
	cin >> n >> k;
	if (k * k - k < n) {
		cout << "NO";
		return 0;
	}
	queue<pair<int, int> > p;
	for (int i = 1; i <= min((int)sqrt(n) + 3, k); i++) {
		for (int j = 1; j <= min((int)sqrt(n) + 3, k); j++) {
			if (i == j) continue;
			p.push({ i, j });
		}
	}
	if (p.size() < n) {
		cout << "NO";
		return 0;
	}
	vector<pair<int, int> > res;
	res.push_back(p.front());
	p.pop();
	while (res.size() < n) {
		pair<int, int> k = p.front();
		p.pop();
		if (res.back().first == k.first || res.back().second == k.second) {
			p.push(k);
		}
		else {
			res.push_back(k);
		}
	}
	cout << "YES\n";
	for (int i = 0; i < n; i++) {
		cout << res[i].first << " " << res[i].second << endl;
	}
	//------------------------------------------------
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <unordered_set>
#include <string>
#include <string.h>
#include <map>
#include <unordered_map>
#include <random>
#include <set>
#include <cassert>
#include <string.h>
#include <limits.h>
#include <stack>
#include <functional>
#include <queue>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <iterator>
#include <algorithm>
#include <sstream>

#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
#define ii pair<int,int>
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >
#define in freopen("arquivoentrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define pi 3.14159265359
#define nl (node<<1)
#define nr ( (node<<1)|1)
//~ #define mid l + ( (r-l)>>1)

const int mod = 998244353;

using namespace std;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long long ll;

using namespace std;

typedef vector<int> vi;
const int maxn = (int)3e5 + 3;
const int MAX = 1e4 + 10;

int ar[maxn];

int n , k;
int main () {

	cin >> n >> k ;

	if (  n > k * k - k )
		return cout << "no\n", 0;
	cout << "yes\n";

	int x = 1;
	for(int i = 1;i <= k;i++){
		ar[i] = ( x )% k;
		x = ( x + 1)% k;
	}

	int a = 0;
	for(int i = 0 ;i < n;i++,a=(a+1)%k){
		cout << a+1 << ' ' << ar[(a+1)]+1 << '\n';
		ar[(a+1)]++;
		ar[(a+1)]%=k;
	}

	return 0;

}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <unordered_set>
#include <string>
#include <string.h>
#include <map>
#include <unordered_map>
#include <random>
#include <set>
#include <cassert>
#include <string.h>
#include <limits.h>
#include <stack>
#include <functional>
#include <queue>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <iterator>
#include <algorithm>
#include <sstream>

#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
#define ii pair<int,int>
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >
#define in freopen("arquivoentrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define pi 3.14159265359
#define nl (node<<1)
#define nr ( (node<<1)|1)
//~ #define mid l + ( (r-l)>>1)

const int mod = 998244353;

using namespace std;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long long ll;

using namespace std;

typedef vector<int> vi;
const int maxn = (int)3e5 + 3;
const int MAX = 1e4 + 10;

int ar[maxn];

int n , k;
int main () {

	cin >> n >> k ;

	if (  n > 1LL*k * 1LL*k - k )
		return cout << "no\n", 0;
	cout << "yes\n";

	int x = 1;
	for(int i = 1;i <= k;i++){
		ar[i] = ( x )% k;
		x = ( x + 1)% k;
	}

	int a = 0;
	for(int i = 0 ;i < n;i++,a=(a+1)%k){
		cout << a+1 << ' ' << ar[(a+1)]+1 << '\n';
		ar[(a+1)]++;
		ar[(a+1)]%=k;
	}

	return 0;

}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <unordered_set>
#include <string>
#include <string.h>
#include <map>
#include <unordered_map>
#include <random>
#include <set>
#include <cassert>
#include <string.h>
#include <limits.h>
#include <stack>
#include <functional>
#include <queue>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <iterator>
#include <algorithm>
#include <sstream>

#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
#define ii pair<int,int>
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >
#define in freopen("arquivoentrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define pi 3.14159265359
#define nl (node<<1)
#define nr ( (node<<1)|1)
//~ #define mid l + ( (r-l)>>1)

const int mod = 998244353;

using namespace std;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long long ll;

using namespace std;

typedef vector<int> vi;
const int maxn = (int)3e5 + 3;
const int MAX = 1e4 + 10;

ii ar[maxn];

int n , k;
int main () {

	cin >> n >> k ;

	if (  n > k * k - k )
		return cout << "no\n", 0;

	for(int i = 0 ;i < n;i++)
		ar[i] = {1 , k };
	cout << "yes\n";

	int a = 0, ant;
	bool up = 1;
	for(int i = 0 ;i < n;i++,a=(a+1)%k){
		if (up and (a+1) == ar[(a+1)].f ){
			ar[(a+1)].f+=1;
		}else if ( !up and (a+1) == ar[(a+1)].s ) {
			ar[(a+1)].s-=1;
		}
		cout << a + 1 << ' ';

		if ( ant == ar[(a+1)].f ){
			ant = ar[(a+1)].s;
			cout<< ar[(a+1)].s << '\n', ar[(a+1)].s-=1;
		}else{
			ant = ar[(a+1)].f;
			cout<< ar[(a+1)].f << '\n', ar[(a+1)].f+=1;
			up ^= 1;
		}
	}

	return 0;

}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <unordered_set>
#include <string>
#include <string.h>
#include <map>
#include <unordered_map>
#include <random>
#include <set>
#include <cassert>
#include <string.h>
#include <limits.h>
#include <stack>
#include <functional>
#include <queue>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <iterator>
#include <algorithm>
#include <sstream>

#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
#define ii pair<int,int>
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >
#define in freopen("arquivoentrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define pi 3.14159265359
#define nl (node<<1)
#define nr ( (node<<1)|1)
//~ #define mid l + ( (r-l)>>1)

const int mod = 998244353;

using namespace std;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long long ll;

using namespace std;

typedef vector<int> vi;
const int maxn = (int)3e5 + 3;
const int MAX = 1e4 + 10;

ii ar[maxn];

int n , k;
int main () {

	cin >> n >> k ;

	if (  n > k * k - k )
		return cout << "no\n", 0;

	for(int i = 0 ;i < n;i++)
		ar[i] = {1 , k };
	cout << "yes\n";

	int a = 0;
	bool up = 1;
	for(int i = 0 ;i < n;i++,a=(a+1)%k){

		if (up and (a+1) == ar[(a+1)].f ){
			ar[(a+1)].f+=1;
		}else if ( !up and (a+1) == ar[(a+1)].s ) {
			ar[(a+1)].s-=1;
		}

		cout << a + 1 << ' ';
		if ( up ){
			cout<< ar[(a+1)].f << '\n';
			ar[(a+1)].f+=1;
		}else{
			cout << ar[(a+1)].s << '\n';
			ar[(a+1)].s-=1;
		}
		up ^= 1;
	}

	return 0;

}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <unordered_set>
#include <string>
#include <string.h>
#include <map>
#include <unordered_map>
#include <random>
#include <set>
#include <cassert>
#include <string.h>
#include <limits.h>
#include <stack>
#include <functional>
#include <queue>
#include <iomanip>
#include <numeric>
#include <bitset>
#include <iterator>
#include <algorithm>
#include <sstream>

#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
#define ii pair<int,int>
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >
#define in freopen("arquivoentrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define pi 3.14159265359
#define nl (node<<1)
#define nr ( (node<<1)|1)
//~ #define mid l + ( (r-l)>>1)

const int mod = 998244353;

using namespace std;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long long ll;

using namespace std;

typedef vector<int> vi;
const int maxn = (int)3e5 + 3;
const int MAX = 1e4 + 10;

ii ar[maxn];

int n , k;
int main () {

	cin >> n >> k ;

	if (  n > k * k - k )
		return cout << "no\n", 0;

	for(int i = 0 ;i < n;i++)
		ar[i] = {1 , k };
	cout << "yes\n";

	int a = 0;
	bool up = 1;
	for(int i = 0 ;i < n;i++,a=(a+1)%k){
		if (up and  (a+1) == ar[i].f ){
			ar[i].f+=1;
		}else if ( !up and (a+1) == ar[i].s ) {
			ar[i].s-=1;
		}

		cout << a + 1 << ' ';
		if ( up ){
			cout<< ar[i].f << '\n';
			ar[i].f+=1;
		}else{
			cout << ar[i].s << '\n';
			ar[i].s-=1;
		}
		up ^= 1;
	}

	return 0;

}


using System;

class Program
{

    static void Main()
    {
        int a, b, n;
        string value;
        String[] substrings2;
        value = Console.ReadLine();
        String[] substrings = value.Split();
        a = Convert.ToInt32(substrings[0]);
        b = Convert.ToInt32(substrings[1]);
        n = Convert.ToInt32(Console.ReadLine());
        int[] x = new int[n];
        int[] y = new int[n];
        int[] v = new int[n];
        for (int i = 0; i < n; i++)
        {
            value = Console.ReadLine();
            substrings2 = value.Split();
            x[i] = Convert.ToInt32(substrings2[0]);
            y[i] = Convert.ToInt32(substrings2[1]);
            v[i] = Convert.ToInt32(substrings2[2]);
        }
        double tmin = 100000;
        double t;
        for (int i = 0; i < n; i++)
        {
            if (x[i]==a&y[i]==b)
            {
                tmin = 0;
                break;
            }
            t = Math.Abs(Math.Sqrt((x[i] - a) * (x[i] - a) + (y[i] - b) * (y[i] - b)) / v[i]);
            if (t < tmin) tmin = t;
        }

        Console.WriteLine(tmin);

    }
}


using System;

class Program
{

    static void Main()
    {
        int a, b, n;
        string value;
        String[] substrings2;
        value = Console.ReadLine();
        String[] substrings = value.Split();
        a = Convert.ToInt32(substrings[0]);
        b = Convert.ToInt32(substrings[1]);
        n = Convert.ToInt32(Console.ReadLine());
        int[] x = new int[n];
        int[] y = new int[n];
        int[] v = new int[n];
        for (int i = 0; i < n; i++)
        {
            value = Console.ReadLine();
            substrings2 = value.Split();
            x[i] = Convert.ToInt32(substrings2[0]);
            y[i] = Convert.ToInt32(substrings2[1]);
            v[i] = Convert.ToInt32(substrings2[2]);
        }
        double tmin = 100000000;
        double t;
        for (int i = 0; i < n; i++)
        {
            t = Math.Sqrt((x[i] - Convert.ToDouble(a)) * (x[i] - Convert.ToDouble(a)) + (y[i] - Convert.ToDouble(b)) * (y[i] - Convert.ToDouble(b))) / Convert.ToDouble(v[i]);
            if (t < tmin) tmin = t;
        }

        Console.WriteLine("{0:0.########}", tmin);

    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int n = Convert.ToInt32(Console.ReadLine());
            double min = double.MaxValue;
            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine().Split();
                int x = int.Parse(s[0]);
                int y = int.Parse(s[1]);
                int v = int.Parse(s[2]);
                double ras = Math.Sqrt((x - a) * (x - a) + (y - b) * (y - b));
                if (ras / v < min)
                {
                    min = ras / v;
                }
            }
            Console.WriteLine(min.ToString().Replace(',','.'));

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int n = Convert.ToInt32(Console.ReadLine());
            double min = double.MaxValue;
            for (int i = 0; i < n; i++)
            {
                s = Console.ReadLine().Split();
                int x = int.Parse(s[0]);
                int y = int.Parse(s[1]);
                int v = int.Parse(s[2]);
                double ras = Math.Sqrt((x - a) * (x - a) + (y - b) * (y - b));
                if (ras / v < min)
                {
                    min = ras / v;
                }
            }
            Console.WriteLine(min.ToString().Replace('.',','));

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Code_160813_01
{
    static void Main()
    {
        string[] s_input = Console.ReadLine().Split();
        int i_point_a = int.Parse(s_input[0]);
        int i_point_b = int.Parse(s_input[1]);
        int i_cars_total = int.Parse(Console.ReadLine());
        List<List<int>> l_cars_info = new List<List<int>>();
        List<double> l_result = new List<double>();
        double d_distance;
        double d_result;

        for (int i = 0; i < i_cars_total; i++)
        {
            List<int> l_3 = new List<int>();
            string[] s_input2 = Console.ReadLine().Split();
            l_3.Add(int.Parse(s_input2[0]));
            l_3.Add(int.Parse(s_input2[1]));
            l_3.Add(int.Parse(s_input2[2]));
            l_cars_info.Add(l_3);
        }

        for (int i = 0; i < i_cars_total; i++)
        {
            d_distance = Math.Sqrt(Math.Pow(i_point_a - l_cars_info[i][0],2)+Math.Pow(i_point_b-l_cars_info[i][1],2));
            d_distance = d_distance / l_cars_info[i][2];
            l_result.Add(d_distance);
        }

        d_result = l_result.Min();
        Console.WriteLine(d_result.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-US")));

    }

}