#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
map<string,int> a;
int d[1100000];
int n;
char s[maxn],b[maxn],e,g;
vector<int> x;
long long ans,u;
bool ch;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",s);
        if(a[s]==0){
            a[s]=1;
            stack<char> f;
            for(int j=0;s[j]!='\0';j++){
                if(f.empty()){
                    f.push(s[j]);
                }
                else{
                    if(f.top()=='('&&s[j]==')'){
                        f.pop();
                        continue;
                    }
                    else{
                        f.push(s[j]);
                    }
                }
            }
            if(!f.empty()){
                    ch=true;
                    e=f.top();
                    g=f.size();
                    while(!f.empty()){
                        if(f.top()!=e)
                            ch=false;
                            f.pop();
                    }
                    if(ch){
                        if(e=='(')
                            d[g]++;
                        else
                            d[int(5e5+1)+g]++;
                    }
                }
                else{
                    d[0]++;
                }
        }
    }
    for(int i=1;i<=int(5e5);i++){
        u=(long long)1*d[i]*d[int(5e5+1)+i];
        ans+=u;
    }
    ans+=(d[0]*(d[0]-1))/2;
    printf("%lld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int d[2100000];
int n,g;
char s[maxn],e;
long long ans,u;
bool ch;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",s);
        //printf("%d",a[s]);
            stack<char> f;
            for(int j=0;s[j]!='\0';j++){
                if(f.empty()){
                    f.push(s[j]);
                }
                else{
                    if(f.top()=='('&&s[j]==')'){
                        f.pop();
                        continue;
                    }
                    else{
                        f.push(s[j]);
                    }
                }
            }
            if(!f.empty()){
                    ch=true;
                    e=f.top();
                    g=f.size();
                    while(!f.empty()){
                        if(f.top()!=e)
                            ch=false;
                            f.pop();
                    }
                    if(ch){
                        if(e=='(')
                            d[g]++;
                        else
                            d[int(1e6)+g]++;
                    }
                }
                else{
                    d[0]++;
                }
    }
    for(int i=1;i<=int(5e5)+55;i++){
        u=min(d[i],d[i+int(1e6)]);
        ans+=u;
    }
    ans+=(d[0])/2;
    printf("%lld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
int d[1100000];
int n,fuck;
char s[maxn],b[maxn],e,g;
vector<int> x;
set<int> t;
long long ans,u;
bool ch;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",s);
        //printf("%d",a[s]);
            stack<char> f;
            for(int j=0;s[j]!='\0';j++){
                if(f.empty()){
                    f.push(s[j]);
                }
                else{
                    if(f.top()=='('&&s[j]==')'){
                        f.pop();
                        continue;
                    }
                    else{
                        f.push(s[j]);
                    }
                }
            }
            if(!f.empty()){
                    ch=true;
                    e=f.top();
                    g=f.size();
                    while(!f.empty()){
                        if(f.top()!=e)
                            ch=false;
                            f.pop();
                    }
                    if(ch){
                        if(e=='(')
                            d[g]++;
                        else
                            d[int(5e5+1)+g]++;
                    }
                }
                else{
                    d[0]++;
                }
    }
    for(int i=1;i<=int(5e5);i++){
        u=min(d[i],d[i+int(5e5+1)]);
        ans+=u;
    }
    ans+=(d[0])/2;
    printf("%lld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
map<string,int> a;
int d[1100000];
int n,c[int(1e6)+10];
char s[maxn],b[maxn];
vector<int> x;
long long ans,u;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",s);
        if(a[s]==0){
            a[s]=1;
            stack<char> f;
            for(int j=0;s[j]!='\0';j++){
                if(f.empty()){
                    f.push(s[j]);
                }
                else{
                    if(f.top()=='('&&s[j]==')'){
                        f.pop();
                        continue;
                    }
                    else{
                        f.push(s[j]);
                    }
                }
            }
            if(!f.empty()){
                    if(f.top()=='(')
                        d[f.size()]++;
                    else
                        d[int(5e5+1)+f.size()]++;
                }
                else{
                    d[0]++;
                }
        }
    }
    for(int i=1;i<=int(5e5);i++){
        u=(long long)1*d[i]*d[int(5e5+1)+i];
        ans+=u;
    }
    ans+=(d[0]*(d[0]-1))/2;
    printf("%lld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
map<string,int> a;
int d[1100000];
int n,fuck;
char s[maxn],b[maxn],e,g;
vector<int> x;
set<int> t;
long long ans,u;
bool ch;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%s",s);
        //printf("%d",a[s]);
            a[s]++;
            stack<char> f;
            for(int j=0;s[j]!='\0';j++){
                if(f.empty()){
                    f.push(s[j]);
                }
                else{
                    if(f.top()=='('&&s[j]==')'){
                        f.pop();
                        continue;
                    }
                    else{
                        f.push(s[j]);
                    }
                }
            }
            if(!f.empty()){
                    if(a[s]==1){
                    ch=true;
                    e=f.top();
                    g=f.size();
                    while(!f.empty()){
                        if(f.top()!=e)
                            ch=false;
                            f.pop();
                    }
                    if(ch){
                        if(e=='(')
                            d[g]++;
                        else
                            d[int(5e5+1)+g]++;
                    }
                }
                }
                else{
                    if(a[s]==1)
                    d[0]++;
                    if(a[s]==2)
                        fuck++;
                }
    }
    for(int i=1;i<=int(5e5);i++){
        u=(long long)1*d[i]*d[int(5e5+1)+i];
        ans+=u;
    }
    ans+=(d[0]*(d[0]-1))/2;
    ans+=fuck;
    printf("%lld\n",ans);
}


#include <bits/stdc++.h>
#define MOD 998244353ll

using namespace std;
long long a[100010];
string s[100010];
long long us1[500010], us2[500010];
unordered_map<string, int> ma;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>> n;
    long long tt = 0;
    for(int i = 1; i <= n; i ++){
        cin>> s[i];
        long long kol = 0;
        for(int j = 0; j < s[i].size(); j ++){
            if(s[i][j] == '('){
                kol++;
            } else{
                kol--;
            }
        }
        a[i] = kol;
       // cout << kol<<'\n';

    }
    long long ans = 0;

    for(int i = 1; i <= n; i ++){
        if(a[i] < 0){
                if (us1[abs(a[i])] > 0) {
                    ans++;
                    us1[abs(a[i])]--;

                } else {
                    us2[abs(a[i])]++;
                }

        } else if(a[i] > 0){
                if(us2[a[i]] > 0) {
                    ans++;
                    us2[a[i]]--;
                }else {
                    us1[a[i]]++;
                }

        } else{
                if(tt > 0) {
                    ans ++;
                    tt--;
                } else {
                    tt++;
                }

        }
        ma[s[i]] = 1;
    }
    cout <<ans;
}


#include <bits/stdc++.h>
#define MOD 998244353ll

using namespace std;
long long a[100010];
string s[100010];
long long us1[500010], us2[500010];
unordered_map<string, int> ma;
vector<int> v;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>> n;
    long long tt = 0;
    for(int i = 1; i <= n; i ++){
        cin>> s[i];
        long long kol = 0, lol = 0;
        for(int j = 0; j < s[i].size(); j ++){
            if(s[i][j] == '('){
                v.push_back(1);
                kol++;
            } else{
                if(v.size() > 0 && v.back() == 1)
                    v.pop_back();
                kol--;
            }
            if(kol < 0){
                lol= 1;
            }
        }
        if(v.size() > 0 && v.back() == 1 && lol == 1){
            s[i] = "-";
        }
        v.clear();
        a[i] = kol;
        // cout << kol<<'\n';

    }
    long long ans = 0;

    for(int i = 1; i <= n; i ++){
        if(s[i] == "-")
            continue;
        if(a[i] < 0){
                if (us1[abs(a[i])] > 0) {
                    ans++;
                    us1[abs(a[i])]--;

                } else {
                    us2[abs(a[i])]++;
                }
        } else if(a[i] > 0){
                if(us2[a[i]] > 0) {
                    ans++;
                    us2[a[i]]--;
                }else {
                    us1[a[i]]++;
                }

        } else{
                if(tt > 0) {
                    ans ++;
                    tt--;
                } else {
                    tt++;
                }
            }

    }
    cout <<ans;
}


#include <bits/stdc++.h>
#define MOD 998244353ll

using namespace std;
long long a[100010];
string s[100010];
long long us1[500010], us2[500010];
unordered_map<string, int> ma;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>> n;
    long long tt = 0;
    for(int i = 1; i <= n; i ++){
        cin>> s[i];
        long long kol = 0;
        for(int j = 0; j < s[i].size(); j ++){
            if(s[i][j] == '('){
                kol++;
            } else{
                kol--;
            }
        }
        a[i] = kol;
       // cout << kol<<'\n';

    }
    long long ans = 0;

    for(int i = 1; i <= n; i ++){
        if(a[i] < 0){
            if(ma[s[i]] == 0) {
                ans += us1[abs(a[i])];
                us2[abs(a[i])]++;
            }
        } else if(a[i] > 0){
            if(ma[s[i]] == 0) {
                ans += us2[a[i]];
                us1[a[i]]++;
            }
        } else{
            if(ma[s[i]] == 0) {
                ans += tt;
                tt++;
            }

        }
        ma[s[i]] = 1;
    }
    cout <<ans;
}


#include <bits/stdc++.h>
#define MOD 998244353ll

using namespace std;
long long a[100010];
string s[100010];
long long us1[500010], us2[500010];
unordered_map<string, int> ma;
vector<int> v;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>> n;
    long long tt = 0;
    for(int i = 1; i <= n; i ++){
        cin>> s[i];
        long long kol = 0, lol = 0;
        for(int j = 0; j < s[i].size(); j ++){
            if(s[i][j] == '('){
                v.push_back(1);
                kol++;
            } else{
                if(v.size() > 0 && v.back() == 1)
                    v.pop_back();
                kol--;
            }
            if(kol < 0){
                lol= 1;
            }
        }
        if(v.back() == 1 && lol == 1){
            s[i] = "-";
        }
        v.clear();
        a[i] = kol;
        // cout << kol<<'\n';

    }
    long long ans = 0;

    for(int i = 1; i <= n; i ++){
        if(s[i] == "-")
            continue;
        if(a[i] < 0){
                if (us1[abs(a[i])] > 0) {
                    ans++;
                    us1[abs(a[i])]--;

                } else {
                    us2[abs(a[i])]++;
                }
        } else if(a[i] > 0){
                if(us2[a[i]] > 0) {
                    ans++;
                    us2[a[i]]--;
                }else {
                    us1[a[i]]++;
                }

        } else{
                if(tt > 0) {
                    ans ++;
                    tt--;
                } else {
                    tt++;
                }
            }

    }
    cout <<ans;
}


#include <bits/stdc++.h>
#define MOD 998244353ll

using namespace std;
long long a[100010];
string s[100010];
long long us1[500010], us2[500010];
unordered_map<string, int> ma;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>> n;
    long long tt = 0;
    for(int i = 1; i <= n; i ++){
        cin>> s[i];
        long long kol = 0;
        for(int j = 0; j < s[i].size(); j ++){
            if(s[i][j] == '('){
                kol++;
            } else{
                kol--;
            }
        }
        a[i] = kol;
       // cout << kol<<'\n';

    }
    long long ans = 0;

    for(int i = 1; i <= n; i ++){
        if(a[i] < 0){
            if(ma[s[i]] == 0) {
                if (us1[abs(a[i])] > 0) {
                    ans++;
                    us1[abs(a[i])]--;

                } else {
                    us2[abs(a[i])]++;
                }
            }
        } else if(a[i] > 0){
            if(ma[s[i]] == 0) {
                if(us2[a[i]] > 0) {
                    ans++;
                    us2[a[i]]--;
                }else {
                    us1[a[i]]++;
                }
            }
        } else{
            if(ma[s[i]] == 0) {
                if(tt > 0) {
                    ans ++;
                    tt--;
                } else {
                    tt++;
                }
            }

        }
        ma[s[i]] = 1;
    }
    cout <<ans;
}


#include <bits/stdc++.h>
#define MOD 998244353ll

using namespace std;
long long a[100010];
string s[100010];
long long us1[500010], us2[500010];
unordered_map<string, int> ma;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>> n;
    long long tt = 0;
    for(int i = 1; i <= n; i ++){
        cin>> s[i];
        long long kol = 0;
        for(int j = 0; j < s[i].size(); j ++){
            if(s[i][j] == '('){
                kol++;
            } else{
                kol--;
            }
        }
        a[i] = kol;
        // cout << kol<<'\n';

    }
    long long ans = 0;

    for(int i = 1; i <= n; i ++){
        if(a[i] < 0){
                if (us1[abs(a[i])] > 0) {
                    ans++;
                    us1[abs(a[i])]--;

                } else {
                    us2[abs(a[i])]++;
                }
        } else if(a[i] > 0){
                if(us2[a[i]] > 0) {
                    ans++;
                    us2[a[i]]--;
                }else {
                    us1[a[i]]++;
                }

        } else{
                if(tt > 0) {
                    ans ++;
                    tt--;
                } else {
                    tt++;
                }
            }

    }
    cout <<ans;
}


#include <bits/stdc++.h>
#define MOD 998244353ll

using namespace std;
long long a[100010];
string s[100010];
long long us1[500010], us2[500010];
unordered_map<string, int> ma;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>> n;
    long long tt = 0;
    for(int i = 1; i <= n; i ++){
        cin>> s[i];
        long long kol = 0, lol = 0;
        for(int j = 0; j < s[i].size(); j ++){
            if(s[i][j] == '('){
                kol++;
            } else{
                kol--;
            }
            if(kol < 0){
                lol = 1;
            }
        }
        if(kol > 0 && lol == 1){
            s[i] = "-";
        }
        a[i] = kol;
        // cout << kol<<'\n';

    }
    long long ans = 0;

    for(int i = 1; i <= n; i ++){
        if(s[i] == "-")
            continue;
        if(a[i] < 0){
                if (us1[abs(a[i])] > 0) {
                    ans++;
                    us1[abs(a[i])]--;

                } else {
                    us2[abs(a[i])]++;
                }
        } else if(a[i] > 0){
                if(us2[a[i]] > 0) {
                    ans++;
                    us2[a[i]]--;
                }else {
                    us1[a[i]]++;
                }

        } else{
                if(tt > 0) {
                    ans ++;
                    tt--;
                } else {
                    tt++;
                }
            }

    }
    cout <<ans;
}


#include <bits/stdc++.h>
#define MOD 998244353ll

using namespace std;
long long a[100010];
string s[100010];
long long us1[500010], us2[500010];
unordered_map<string, int> ma;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>> n;
    long long tt = 0;
    for(int i = 1; i <= n; i ++){
        cin>> s[i];
        long long kol = 0;
        for(int j = 0; j < s[i].size(); j ++){
            if(s[i][j] == '('){
                kol++;
            } else{
                kol--;
            }
        }
        a[i] = kol;
       // cout << kol<<'\n';

    }
    long long ans = 0;

    for(int i = 1; i <= n; i ++){
        if(a[i] < 0){
            if(ma[s[i]] == 0) {
                ans += us1[abs(a[i])];
                us2[abs(a[i])]++;
            }
        } else if(a[i] > 0){
            if(ma[s[i]] == 0) {
                ans += us1[a[i]];
                us1[a[i]]++;
            }
        } else{
            if(ma[s[i]] == 0) {
                ans += tt;
                tt++;
            }

        }
        ma[s[i]] = 1;
    }
    cout <<ans;
}


#include <bits/stdc++.h>
#define MOD 998244353ll

using namespace std;
long long a[100010];
string s[100010];
long long us1[500010], us2[500010];
unordered_map<string, int> ma;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>> n;
    long long tt = 0;
    for(int i = 1; i <= n; i ++){
        cin>> s[i];
        long long kol = 0, lol = 0;
        for(int j = 0; j < s[i].size(); j ++){
            if(s[i][j] == '('){
                kol++;
            } else{
                kol--;
            }
            if(kol < 0){
                lol = 1;
            }
        }
        if(kol >= 0 && lol == 1){
            s[i] = "-";
        }
        a[i] = kol;
        // cout << kol<<'\n';

    }
    long long ans = 0;

    for(int i = 1; i <= n; i ++){
        if(s[i] == "-")
            continue;
        if(a[i] < 0){
                if (us1[abs(a[i])] > 0) {
                    ans++;
                    us1[abs(a[i])]--;

                } else {
                    us2[abs(a[i])]++;
                }
        } else if(a[i] > 0){
                if(us2[a[i]] > 0) {
                    ans++;
                    us2[a[i]]--;
                }else {
                    us1[a[i]]++;
                }

        } else{
                if(tt > 0) {
                    ans ++;
                    tt--;
                } else {
                    tt++;
                }
            }

    }
    cout <<ans;
}


#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
struct Node{
	string str;
	int cnt;
}Edge[maxn];
typedef pair<char,int> p;
map<pair<char,int>,int> ma;
int num,xx;
int n;

int main()
{
	num = 0;
	xx = 0;
	scanf("%d",&n);
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		int len = s.length();
		stack<char> ss;
		bool flag = true;
		for(int j=0;j<len;j++){
			if(ss.size() == 0){
				ss.push(s[j]);
				continue;
			}
			if(ss.top() == '(' && s[j] == ')')ss.pop();
			else if(ss.top() == ')' && s[j] == '('){
				flag = false;
				break;
			}
			else ss.push(s[j]);
		}
		if(flag == false){
			continue;
		}
		else{
			if(ss.size() == 0){
				xx ++;
				continue;
			}
			Edge[num].cnt = ss.size();
			string ch;
			while(!ss.empty()){
				ch += ss.top();
				ss.pop();
			}
			reverse(ch.begin(), ch.end());
			Edge[num++].str = ch;
			ma[p(ch[0], Edge[num - 1].cnt)] ++;
		}
	}
	int ans = 0;
	for(int i=0;i<num;i++){
		if(Edge[i].str[0] == '(' && ma[p(')', Edge[i].cnt)] != 0){
			ans += min(ma[p(Edge[i].str[0], Edge[i].cnt)], ma[p(')', Edge[i].cnt)]);
		}
		if(Edge[i].str[0] == ')' && ma[p('(', Edge[i].cnt)] != 0){
			ans += min(ma[p(Edge[i].str[0], Edge[i].cnt)], ma[p('(', Edge[i].cnt)]);
		}
	}
	printf("%d\n", int(ceil((ans + xx) / 2)));
	return 0;
}


#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
struct Node{
	string str;
	int cnt;
}Edge[maxn];
typedef pair<char,int> p;
map<pair<char,int>,int> ma;
int num;
int n;

int main()
{
	num = 0;
	scanf("%d",&n);
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		int len = s.length();
		stack<char> ss;
		bool flag = true;
		for(int j=0;j<len;j++){
			if(ss.size() == 0){
				ss.push(s[j]);
				continue;
			}
			if(ss.top() == '(' && s[j] == ')')ss.pop();
			else if(ss.top() == ')' && s[j] == '('){
				flag = false;
				break;
			}
			else ss.push(s[j]);
		}
		if(flag == false){
			continue;
		}
		else{
			Edge[num].cnt = ss.size();
			string ch;
			while(!ss.empty()){
				ch += ss.top();
				ss.pop();
			}
			reverse(ch.begin(), ch.end());
			Edge[num++].str = ch;
			ma[p(ch[0], Edge[num - 1].cnt)] ++;
		}
	}
	int ans = 0;
	for(int i=0;i<num;i++){
		if(Edge[i].str[0] == '(' && ma[p(')', Edge[i].cnt)] != 0){
			ans += min(ma[p(Edge[i].str[0], Edge[i].cnt)], ma[p(')', Edge[i].cnt)]);
		}
		if(Edge[i].str[0] == ')' && ma[p('(', Edge[i].cnt)] != 0){
			ans += min(ma[p(Edge[i].str[0], Edge[i].cnt)], ma[p('(', Edge[i].cnt)]);
		}
	}
	printf("%d\n", ans / 2);
	return 0;
}


#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
struct Node{
	string str;
	int cnt;
}Edge[maxn];
typedef pair<char,int> p;
map<pair<char,int>,int> ma;
int num,xx;
int n;

int main()
{
	num = 0;
	xx = 0;
	scanf("%d",&n);
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		int len = s.length();
		stack<char> ss;
		bool flag = true;
		for(int j=0;j<len;j++){
			if(ss.size() == 0){
				ss.push(s[j]);
				continue;
			}
			if(ss.top() == '(' && s[j] == ')')ss.pop();
			else if(ss.top() == ')' && s[j] == '('){
				flag = false;
				break;
			}
			else ss.push(s[j]);
		}
		if(flag == false){
			continue;
		}
		else{
			if(ss.size() == 0){
				xx ++;
				continue;
			}
			Edge[num].cnt = ss.size();
			string ch;
			while(!ss.empty()){
				ch += ss.top();
				ss.pop();
			}
			reverse(ch.begin(), ch.end());
			Edge[num++].str = ch;
			ma[p(ch[0], Edge[num - 1].cnt)] ++;
		}
	}
	int ans = 0;
	for(int i=0;i<num;i++){
		if(Edge[i].str[0] == '(' && ma[p(')', Edge[i].cnt)] != 0){
			ans += min(ma[p(Edge[i].str[0], Edge[i].cnt)], ma[p(')', Edge[i].cnt)]);
		}
		if(Edge[i].str[0] == ')' && ma[p('(', Edge[i].cnt)] != 0){
			ans += min(ma[p(Edge[i].str[0], Edge[i].cnt)], ma[p('(', Edge[i].cnt)]);
		}
	}
	printf("%d\n", (ans + xx) / 2);
	return 0;
}


#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
struct Node{
	string str;
	int cnt;
}Edge[maxn];
typedef pair<char,int> p;
map<pair<char,int>,int> ma;
int num,xx;
int n;

int main()
{
	num = 0;
	xx = 0;
	scanf("%d",&n);
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		int len = s.length();
		stack<char> ss;
		bool flag = true;
		map<char,int> yy;
		for(int j=0;j<len;j++){
			if(ss.size() == 0){
				ss.push(s[j]);
				yy[s[j]]++;
				continue;
			}
			if(ss.top() == '(' && s[j] == ')'){
				yy[ss.top()] --;
				ss.pop();
			}
			// else if(ss.top() == ')' && s[j] == '('){
			// 	flag = false;
			// 	break;
			// }
			else{
				ss.push(s[j]);
				yy[s[j]]++;
			}
		}
		if(yy[')'] != 0 && yy['('] != 0){
			// cout<<yy[')']<<"   "<<yy['(']<<endl;
			continue;
		}
		else{
			if(ss.size() == 0){
				xx ++;
				continue;
			}
			Edge[num].cnt = ss.size();
			string ch;
			while(!ss.empty()){
				ch += ss.top();
				ss.pop();
			}
			reverse(ch.begin(), ch.end());
			Edge[num++].str = ch;
			ma[p(ch[0], Edge[num - 1].cnt)] ++;
		}
	}
	for(int i=0;i<num;i++){
		cout<<Edge[i].str<<"  "<<Edge[i].cnt<<endl;
	}
	int ans = 0;
	for(int i=0;i<num;i++){
		if(Edge[i].str[0] == '(' && ma[p(')', Edge[i].cnt)] != 0){
			ans += min(ma[p(Edge[i].str[0], Edge[i].cnt)], ma[p(')', Edge[i].cnt)]);
		}
		if(Edge[i].str[0] == ')' && ma[p('(', Edge[i].cnt)] != 0){
			ans += min(ma[p(Edge[i].str[0], Edge[i].cnt)], ma[p('(', Edge[i].cnt)]);
		}
	}
	ans += xx / 2;
	printf("%d\n", ans / 2);
	return 0;
}


#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
struct Node{
	string str;
	int cnt;
}Edge[maxn];
struct node{
	string str;
	int cnt;
}edge[maxn];
typedef pair<char,int> p;
map<pair<char,int>,int> ma;
int num,xx,num1;
int n;

int main()
{
	num = 0;
	num1 = 0;
	xx = 0;
	scanf("%d",&n);
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		int len = s.length();
		stack<char> ss;
		bool flag = true;
		map<char,int> yy;
		for(int j=0;j<len;j++){
			if(ss.size() == 0){
				ss.push(s[j]);
				yy[s[j]]++;
				continue;
			}
			if(ss.top() == '(' && s[j] == ')'){
				yy[ss.top()] --;
				ss.pop();
			}
			else{
				ss.push(s[j]);
				yy[s[j]]++;
			}
		}
		if(yy[')'] != 0 && yy['('] != 0){
			continue;
		}
		else{
			if(ss.size() == 0){
				xx ++;
				continue;
			}
			if(ss.top() == '('){
				Edge[num].cnt = ss.size();
				string ch;
				while(!ss.empty()){
					ch += ss.top();
					ss.pop();
				}
				reverse(ch.begin(), ch.end());
				Edge[num++].str = ch;
				ma[p(ch[0], Edge[num - 1].cnt)] ++;
			}
			else{
				edge[num1].cnt = ss.size();
				string ch;
				while(!ss.empty()){
					ch += ss.top();
					ss.pop();
				}
				reverse(ch.begin(), ch.end());
				edge[num1++].str = ch;
				ma[p(ch[0], edge[num1 - 1].cnt)] ++;
			}
		}
	}
	for(int i=0;i<num;i++){
		cout<<Edge[i].str<<"  "<<Edge[i].cnt<<endl;
	}
	int ans = 0;

	for(int i=0;i<num;i++){
		if(ma[p(')', Edge[i].cnt)] != 0){
			ans += min(ma[p('(',Edge[i].cnt)], ma[p('(',Edge[i].cnt)]);
		}
	}
	// cout<<xx<<endl;
	ans += xx / 2;
	printf("%d\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define maxn 500005
#define inf 0x3f3f3f3f
using namespace std;
int n,yy;
int p[maxn],m[maxn];
string str;

int main()
{
	yy = 0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin>>str;
		int len = str.length();
		int Min = 0;
		int xx = 0;
		for(int j=0;j<len;j++){
			if(str[j] == '(') xx ++;
			else xx --;
			Min = min(Min, xx);
		}
		if(Min == 0 && xx == 0){
			yy ++;
		}
		else if(Min == 0){
			p[xx] ++;
		}
		else if(Min < 0 && Min == xx){
			m[-xx] ++;
		}
	}
	int ans = yy / 2;
	for(int i=0;i<maxn;i++){
		ans += min(p[i], m[i]);
	}
	printf("%d\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define maxn 500005
#define inf 0x3f3f3f3f
using namespace std;
int n,yy;
map<int,int> m,p;
string str;

int main()
{
	yy = 0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin>>str;
		int len = str.length();
		int Min = 0;
		int xx = 0;
		for(int j=0;j<len;j++){
			if(str[j] == '(') xx ++;
			else xx --;
			Min = min(Min, xx);
		}
		if(Min == 0 && xx == 0){
			yy ++;
		}
		else if(Min == 0){
			p[xx] ++;
		}
		else if(Min < 0 && Min == xx){
			m[-xx] ++;
		}
	}
	int ans = yy / 2;
	for(int i=0;i<maxn;i++){
		ans += min(p[i], m[i]);
	}
	printf("%d\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
struct Node{
	string str;
	int cnt;
}Edge[maxn];
typedef pair<char,int> p;
map<pair<char,int>,int> ma;
int num,xx;
int n;

int main()
{
	num = 0;
	xx = 0;
	scanf("%d",&n);
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		int len = s.length();
		stack<char> ss;
		bool flag = true;
		for(int j=0;j<len;j++){
			if(ss.size() == 0){
				ss.push(s[j]);
				continue;
			}
			if(ss.top() == '(' && s[j] == ')')ss.pop();
			else if(ss.top() == ')' && s[j] == '('){
				flag = false;
				break;
			}
			else ss.push(s[j]);
		}
		if(flag == false){
			continue;
		}
		else{
			if(ss.size() == 0){
				xx ++;
				continue;
			}
			Edge[num].cnt = ss.size();
			string ch;
			while(!ss.empty()){
				ch += ss.top();
				ss.pop();
			}
			reverse(ch.begin(), ch.end());
			Edge[num++].str = ch;
			ma[p(ch[0], Edge[num - 1].cnt)] ++;
		}
	}
	int ans = 0;
	for(int i=0;i<num;i++){
		if(Edge[i].str[0] == '(' && ma[p(')', Edge[i].cnt)] != 0){
			ans += min(ma[p(Edge[i].str[0], Edge[i].cnt)], ma[p(')', Edge[i].cnt)]);
		}
		if(Edge[i].str[0] == ')' && ma[p('(', Edge[i].cnt)] != 0){
			ans += min(ma[p(Edge[i].str[0], Edge[i].cnt)], ma[p('(', Edge[i].cnt)]);
		}
	}
	printf("%d\n", ceil((ans + xx) / 2));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 100009
string s[w];
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
bool check(ll i,ll j)
{
	string u=s[i]+s[j];
	stack<char>a;
	a.push(u[0]);
	for(ll j=1;j<u.length();j++)
	{
		if(u[j]==')')
		{
			if(!a.empty()&&a.top()=='(')
			a.pop();
			else
			a.push(u[j]);
		}
		else
		a.push(u[j]);
	}
	if(a.empty())
	return true;
	return false;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	ll close[w]={0};
	ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	cin>>s[i];
	ll sum[w]={0};
	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<s[i].length();j++)
		{
			if(s[i][j]=='(')
			sum[i]--;
			else
			sum[i]++;
		}
	}
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(vis[i])
		continue;
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if((sum[i]+sum[j])==0)
			{
				if(check(i,j)||check(j,i))
				{
					vis[i]=vis[j]=true;
					count++;
					break;
				}
			}
		}
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 1000009
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	string s[w];
	ll close[w]={0};
	ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	{
		cin>>s[i];
		stack<char>a;
		a.push(s[i][0]);
		for(ll j=1;j<s[i].length();j++)
		{
			if(a.top()=='(' && s[i][j]==')')
			a.pop();
			else
			a.push(s[i][j]);
		}
		while(!a.empty())
		{
			if(a.top()=='(')
			close[i]++;
			else
			open[i]++;
			a.pop();
		}
		/*test2(open[i],close[i]);*/
	}
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(!vis[i])
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if(open[i]==close[j] && close[i]==open[j])
			{
				//test2(i,j);
				vis[i]=vis[j]=true;
				count++;
				break;
			}
		}
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 100009
string s[w];
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
bool check(ll i,ll j)
{
	//for(ll i=1;i<=n;i++)
	//{
		//cin>>s[i];
		string u=s[i]+s[j];
		stack<char>a;
		a.push(u[0]);
		for(ll j=1;j<u.length()/*&&!a.empty()*/;j++)
		{
			if(u[j]==')')
			{
				if(!a.empty()&&a.top()=='(')
				a.pop();
				else
				a.push(u[j]);
			}
			else
			a.push(u[j]);
		}
		if(a.empty())
		{
			test1(u);
			return true;
		}
		return false;
		//test2(open[i],close[i]);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	ll close[w]={0};
	ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	{
		cin>>s[i];
	}
		/*stack<char>a;
		a.push(s[i][0]);
		for(ll j=1;j<s[i].length()&&!a.empty();j++)
		{
			if(  (a.top()=='(' && s[i][j]==')'))
			a.pop();
			else
			a.push(s[i][j]);
		}
		while(!a.empty())
		{
			if(a.top()=='(')
			close[i]++;
			else
			open[i]++;
			a.pop();
		}
		//test2(open[i],close[i]);
	}*/
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(vis[i])
		continue;
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if(check(i,j)||check(j,i))
			{
				test2(i,j);
				vis[i]=vis[j]=true;
				count++;
				break;
			}
		}
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 100009
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	string s[w];
	ll close[w]={0};
	ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	{
		cin>>s[i];
		stack<char>a;
		a.push(s[i][0]);
		for(ll j=1;j<s[i].length()&&!a.empty();j++)
		{
			if(  (a.top()=='(' && s[i][j]==')'))
			a.pop();
			else
			a.push(s[i][j]);
		}
		while(!a.empty())
		{
			if(a.top()=='(')
			close[i]++;
			else
			open[i]++;
			a.pop();
		}
		//test2(open[i],close[i]);
	}
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(!vis[i])
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if(open[i]==close[j] && close[i]==open[j])
			{
			//	test2(i,j);
				vis[i]=vis[j]=true;
				count++;
				break;
			}
		}
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	string s[100009];
	ll close[100009]={0};ll open[100009]={0};
	bool vis[100009]={false};
	for(ll i=1;i<=n;i++)
	{
		cin>>s[i];
		stack<char>a;
		a.push(s[i][0]);
		for(ll j=1;j<s[i].length();j++)
		{
			if(a.top()=='(' && s[i][j]==')')
			a.pop();
			else
			a.push(s[i][j]);
		}
		while(!a.empty())
		{
			if(a.top()=='(')
			close[i]++;
			else
			open[i]++;
			a.pop();
		}
		/*test2(open[i],close[i]);*/
	}
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(!vis[i])
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if(open[i]==close[j] && close[i]==open[j])
			{
				//test2(i,j);
				vis[i]=vis[j]=true;
				count++;
				break;
			}
		}
	}
	cout<<count<<endl;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int len = (int) s.size();
    int cnt_open = 0;
    int cnt_close = 0;
    for (char c : s) {
      cnt_open += (c == '(');
      cnt_close += (c == ')');
    }
    int bal = 0;
    for (int j = 0; j < len; j++) {
      if (s[j] == '(') bal++; else {
        if (bal > 0) {
          cnt_open--;
          cnt_close--;
          bal--;
        }
      }
    }
    if (cnt_open > 0 && cnt_close > 0) {
      continue;
    }
    a.push_back(cnt_open - cnt_close);
  }
  sort(a.begin(), a.end());
  int ans = 0;
  int i = 0, j = (int) a.size() - 1;
  while (i < j) {
    if (a[i] + a[j] == 0) {
      ans++;
      i++;
      j--;
    } else {
      if (a[i] + a[j] > 0) {
        j--;
      } else {
        i++;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 500009
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	string s[w];
	ll close[w]={0};ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	{
		cin>>s[i];
		stack<char>a;
		a.push(s[i][0]);
		for(ll j=1;j<s[i].length();j++)
		{
			if(a.top()=='(' && s[i][j]==')')
			a.pop();
			else
			a.push(s[i][j]);
		}
		while(!a.empty())
		{
			if(a.top()=='(')
			close[i]++;
			else
			open[i]++;
			a.pop();
		}
		/*test2(open[i],close[i]);*/
	}
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(!vis[i])
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if(open[i]==close[j] && close[i]==open[j])
			{
				//test2(i,j);
				vis[i]=vis[j]=true;
				count++;
				break;
			}
		}
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 100009
string s[w];
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
bool check(ll i,ll j)
{
	//for(ll i=1;i<=n;i++)
	//{
		//cin>>s[i];
		string u=s[i]+s[j];
		stack<char>a;
		a.push(u[0]);
		for(ll j=1;j<u.length()/*&&!a.empty()*/;j++)
		{
			if(u[j]==')')
			{
				if(!a.empty()&&a.top()=='(')
				a.pop();
				else
				a.push(u[j]);
			}
			else
			a.push(u[j]);
		}
		if(a.empty())
		{
			//test1(u);
			return true;
		}
		return false;
		//test2(open[i],close[i]);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	ll close[w]={0};
	ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	{
		cin>>s[i];
	}
		/*stack<char>a;
		a.push(s[i][0]);
		for(ll j=1;j<s[i].length()&&!a.empty();j++)
		{
			if(  (a.top()=='(' && s[i][j]==')'))
			a.pop();
			else
			a.push(s[i][j]);
		}
		while(!a.empty())
		{
			if(a.top()=='(')
			close[i]++;
			else
			open[i]++;
			a.pop();
		}
		//test2(open[i],close[i]);
	}*/
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(vis[i])
		continue;
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if(check(i,j)||check(j,i))
			{
				//test2(i,j);
				vis[i]=vis[j]=true;
				count++;
				break;
			}
		}
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 100009
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	string s[w];
	ll close[w]={0};
	ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	{
		cin>>s[i];
		stack<char>a;
		a.push(s[i][0]);
		for(ll j=1;j<s[i].length()&&!a.empty();j++)
		{
			if(  (a.top()=='(' && s[i][j]==')')  ||  (a.top()==')' && s[i][j]=='(')  )
			a.pop();
			else
			a.push(s[i][j]);
		}
		while(!a.empty())
		{
			if(a.top()=='(')
			close[i]++;
			else
			open[i]++;
			a.pop();
		}
		/*test2(open[i],close[i]);*/
	}
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(!vis[i])
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if(open[i]==close[j] && close[i]==open[j])
			{
				//test2(i,j);
				vis[i]=vis[j]=true;
				count++;
				break;
			}
		}
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 1000009
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	string s[w];
	ll close[w]={0};
	ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	{
		cin>>s[i];
		stack<char>a;
		a.push(s[i][0]);
		for(ll j=1;j<s[i].length();j++)
		{
			if((a.top()=='(' && s[i][j]==')')||(a.top()==')' && s[i][j]=='('))
			a.pop();
			else
			a.push(s[i][j]);
		}
		while(!a.empty())
		{
			if(a.top()=='(')
			close[i]++;
			else
			open[i]++;
			a.pop();
		}
		/*test2(open[i],close[i]);*/
	}
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(!vis[i])
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if(open[i]==close[j] && close[i]==open[j])
			{
				//test2(i,j);
				vis[i]=vis[j]=true;
				count++;
				break;
			}
		}
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 100009
string s[w];
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
bool check(ll i,ll j)
{
	string u=s[i]+s[j];
	stack<char>a;
	a.push(u[0]);
	for(ll j=1;j<u.length();j++)
	{
		if(u[j]==')')
		{
			if(!a.empty()&&a.top()=='(')
			a.pop();
			else
			a.push(u[j]);
		}
		else
		a.push(u[j]);
	}
	if(a.empty())
	return true;
	return false;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	ll close[w]={0};
	ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	cin>>s[i];
	ll sum[w]={0};
	map<ll,ll>mp;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<s[i].length();j++)
		{
			if(s[i][j]=='(')
			sum[i]--;
			else
			sum[i]++;
		}
		mp[sum[i]]++;
	}
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(vis[i])
		continue;
		ll x=sum[i];
		if(mp.find(-x)==mp.end())
		continue;
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if((sum[i]+sum[j])==0)
			{
				if(check(i,j)||check(j,i))
				{
					vis[i]=vis[j]=true;
					count++;
					mp[x]--;mp[-x]--;
					break;
				}
			}
		}
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 100009
string s[w];
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
bool check(ll i,ll j)
{
	string u=s[i]+s[j];
	stack<char>a;
	a.push(u[0]);
	for(ll j=1;j<u.length();j++)
	{
		if(u[j]==')')
		{
			if(!a.empty()&&a.top()=='(')
			a.pop();
			else
			a.push(u[j]);
		}
		else
		a.push(u[j]);
	}
	if(a.empty())
	return true;
	return false;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	ll close[w]={0};
	ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	cin>>s[i];
	ll sum[w]={0};
	map<ll,ll>mp;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<s[i].length();j++)
		{
			if(s[i][j]=='(')
			sum[i]--;
			else
			sum[i]++;
		}
		mp[sum[i]]++;
	}
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(vis[i])
		continue;
		ll x=sum[i];
		if(mp.find(-x)==mp.end())
		continue;
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if((sum[i]+sum[j])==0)
			{
				if(check(i,j)||check(j,i))
				{
					/*test2(i,j);*/
					vis[i]=vis[j]=true;
					count++;
					mp[x]--;mp[-x]--;
					if(mp[x]==0)
					mp.erase(x);
					if(mp[-x]==0)
					mp.erase(-x);
					break;
				}
			}
		}
	}
	cout<<count<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define make make_pair
#define ff first
#define ss second
#define hell 1000000007
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define w 100009
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        ll n;cin>>n;
	string s[w];
	ll close[w]={0};
	ll open[w]={0};
	bool vis[w]={false};
	for(ll i=1;i<=n;i++)
	{
		cin>>s[i];
		stack<char>a;
		a.push(s[i][0]);
		for(ll j=1;j<s[i].length();j++)
		{
			if((a.top()=='(' && s[i][j]==')')||(a.top()==')' && s[i][j]=='('))
			a.pop();
			else
			a.push(s[i][j]);
		}
		while(!a.empty())
		{
			if(a.top()=='(')
			close[i]++;
			else
			open[i]++;
			a.pop();
		}
		/*test2(open[i],close[i]);*/
	}
	ll count=0;
	for(ll i=1;i<n;i++)
	{
		if(!vis[i])
		for(ll j=i+1;j<=n;j++)
		{
			if(vis[j])
			continue;
			if(open[i]==close[j] && close[i]==open[j])
			{
				//test2(i,j);
				vis[i]=vis[j]=true;
				count++;
				break;
			}
		}
	}
	cout<<count<<endl;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>

typedef std::vector<int> vi;
typedef std::pair<int, int> pii;

const int MAX = 500005;

std::pair<int, int> get_count(std::string& s) {
    std::vector<char> stk;
    int cnt = 0;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '(') stk.push_back(s[i]);
        else {
            if (stk.empty()) cnt++;
            else stk.pop_back();
        }
    }

    return {cnt, (int) stk.size()};
}

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

    int n;
    std::cin >> n;

    int cc = 0, res = 0;

    vi top(MAX, 0);
    vi bottom(MAX, 0);
    for (int i = 0; i < n; i++) {
        std::string temp;
        std::cin >> temp;

        pii cnt = get_count(temp);
        if (cnt.first == 0 && cnt.second == 0) {
            cc++;
        } else if(cnt.first == 0) {
            if (top[cnt.second] > 0) {
                top[cnt.second]--;
                res++;
            } else {
                bottom[cnt.second]++;
            }
        } else if (cnt.second == 0) {
            if (bottom[cnt.first] > 0) {
                bottom[cnt.first]--;
                res++;
            } else {
                top[cnt.first]++;
            }
        }
    }
    std::cout << res + (cc/2) << "\n";
}


#include <iostream>
#include <vector>
#include <string>
#include <set>

typedef std::vector<int> vi;
typedef std::pair<int, int> pii;

std::pair<int, int> get_count(std::string s) {
    std::vector<char> stk;
    int f = 0;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '(') stk.push_back(s[i]);
        else {
            if (stk.empty()) f++;
            else stk.pop_back();
        }
    }

    return {f, (int) stk.size()};
}

bool valid(std::pair<int, int>& p1, std::pair<int, int>& p2) {
    return p1.first == 0 && p2.second == 0 && (p1.second == p2.first);
}

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

    int n;
    std::cin >> n;

    std::vector<std::string> arr(n);
    for (int i = 0; i < n; i++) {
        std::cin >> arr[i];
    }

    std::vector<std::pair<int,int> > cache;
    for (std::string ss : arr) {
        cache.push_back(get_count(ss));
    }

    std::vector<int> okay(n, 0);
    int res = 0;
    int cc = 0;

    for (int i = 0; i < cache.size(); i++) {
        if (cache[i].first == 0 && cache[i].second == 0) {
            okay[i] = 1;
            cc++;
        }
    }

    for (int i = 0; i < cache.size(); i++) {
        if (okay[i]) continue;

        std::pair<int,int> p1 = cache[i];
        for (int j = 0; j < cache.size(); j++) {
            if (okay[j] || i == j) continue;

            std::pair<int,int> p2 = cache[j];
            if (valid(p1, p2)) {
                res++;
                okay[i] = 1;
                okay[j] = 1;
                break;
            }
        }
    }

    std::cout << res + (cc/2) << "\n";
}


#include <iostream>
#include <vector>
#include <string>
#include <set>

typedef std::vector<int> vi;

const int MAX = 100005;

vi graph[MAX];
vi vis;
vi match;

bool valid(std::string s) {
    std::vector<char> stk;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '(') stk.push_back(s[i]);
        else {
            if (stk.empty()) return 0;
            stk.pop_back();
        }
    }
    return stk.empty();
}

int aug(int x) {
    if (vis[x]) return 0;
    vis[x] = 1;
    for (int v : graph[x]) {
        if (match[v] == -1 || aug(match[v])) {
            match[v] = x;
            return 1;
        }
    }

    return 0;
}

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

    int n;
    std::cin >> n;

    std::vector<std::string> arr(n);
    for (int i = 0; i < n; i++) {
        std::cin >> arr[i];
    }

    std::set<int> available;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            if (valid(arr[i]+arr[j])) {
                //std::cout << i << " " << j << '\n';
                graph[i].push_back(j);
                available.insert(i);
            }
        }
    }

    match.assign(MAX, -1);

    int res = 0;
    for (int x : available) {
        if (match[x] != -1) continue;
        vis.assign(MAX, 0);
        res += aug(x);
    }

    std::cout << res << "\n";
}


#include <iostream>
#include <vector>
#include <string>
#include <set>

typedef std::vector<int> vi;
typedef std::pair<int, int> pii;

std::pair<int, int> get_count(std::string& s) {
    std::vector<char> stk;
    int cnt = 0;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '(') stk.push_back(s[i]);
        else {
            if (stk.empty()) cnt++;
            else stk.pop_back();
        }
    }

    return {cnt, (int) stk.size()};
}

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

    int n;
    std::cin >> n;

    int cc = 0, res = 0;
    std::vector<std::pair<int,int> > store;

    vi top(n, 0);
    vi bottom(n, 0);
    for (int i = 0; i < n; i++) {
        std::string temp;
        std::cin >> temp;

        pii cnt = get_count(temp);
        if (cnt.first == 0 && cnt.second == 0) {
            cc++;
        } else if(cnt.first == 0) {
            if (top[cnt.second] != 0) {
                top[cnt.second]--;
                res++;
            } else {
                bottom[cnt.second]++;
            }
        } else if (cnt.second == 0) {
            if (bottom[cnt.first] != 0) {
                bottom[cnt.first]--;
                res++;
            } else {
                top[cnt.first]++;
            }
        }
    }
    std::cout << res + (cc/2) << "\n";
}


#include<bits/stdc++.h>
using namespace std;
#define Getchar() (P1==P2&&(P2=(P1=BUF)+fread(BUF,1,1<<21,stdin),P1==P2)?EOF:*P1++)
char BUF[1<<21],*P1=BUF,*P2=BUF;
inline int read()
{
	int res=0,f=1;
	char ch=Getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=Getchar();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+ch-48,ch=Getchar();
	return res*f;
}
const int N=51;
int n,m,x[N],y[N],st1[N],st2[N];
int r[N],du[N];
bool cmp1(int a,int b)
{
	return x[a]<x[b];
}
bool cmp2(int a,int b)
{
	return y[a]<y[b];
}
int main()
{
	n=read();m=read();
	if(m>n)
	{
		printf("NO\n");
		return 0;
	}
	for(int i=1,x,y;i<=m;i++)
	{
		x=read();y=read();
		if(r[x]!=y&&r[x]!=0)
		{
			printf("NO\n");
			return 0;
		}
		du[y]++;
		r[x]=y;
	}
	x[0]=1;
	for(int i=1;i<=n;i++)
	{
		if(du[i]==0)
		{
			++y[0];
			y[y[0]]=i;
			int now=i;
			while(r[now])now=r[now];
			x[0]++;
			x[x[0]]=now;
		}
	}
	x[1]=x[x[0]];
	x[0]--;
	for(int i=1;i<=x[0];i++)st1[i]=st2[i]=i;
	sort(st1+1,st1+x[0]+1,cmp1);
	sort(st2+1,st2+x[0]+1,cmp2);
	printf("YES\n");
	printf("%d\n",x[0]);
	if(x[1]<y[1])
	{
		for(int i=1;i<=x[0];i++)
			printf("%d %d\n",x[i],y[i]);
	}
	else if(x[1]>y[1])
	{
		for(int i=1;i<=x[0];i++)
			printf("%d %d\n",y[i],x[i]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Getchar() (P1==P2&&(P2=(P1=BUF)+fread(BUF,1,1<<21,stdin),P1==P2)?EOF:*P1++)
char BUF[1<<21],*P1=BUF,*P2=BUF;
inline int read()
{
	int res=0,f=1;
	char ch=Getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=Getchar();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+ch-48,ch=Getchar();
	return res*f;
}
const int N=51;
int n,m,x[N],y[N],st1[N],st2[N];
int r[N],du[N];
bool cmp1(int a,int b)
{
	return x[a]<x[b];
}
bool cmp2(int a,int b)
{
	return y[a]<y[b];
}
int main()
{
	n=read();m=read();
	if(m>n)
	{
		printf("NO\n");
		return 0;
	}
	for(int i=1,x,y;i<=m;i++)
	{
		x=read();y=read();
		if(r[x]!=y&&r[x]!=0)
		{
			printf("NO\n");
			return 0;
		}
		du[y]++;
		r[x]=y;
	}
	x[0]=1;
	for(int i=1;i<=n;i++)
	{
		if(du[i]==0)
		{
			++y[0];
			y[y[0]]=i;
			int now=i;
			while(r[now])now=r[now];
			x[0]++;
			x[x[0]]=now;
		}
	}
	x[1]=x[x[0]];
	x[0]--;
	for(int i=1;i<=x[0];i++)st1[i]=st2[i]=i;
	sort(st1+1,st1+x[0]+1,cmp1);
	sort(st2+1,st2+x[0]+1,cmp2);
	printf("YES\n");
	printf("%d\n",x[0]);
	if(x[1]<y[1])
	{
		for(int i=1;i<=x[0];i++)
			printf("%d %d\n",x[st1[i]],y[st1[i]]);
	}
	else if(x[1]>y[1])
	{
		for(int i=1;i<=x[0];i++)
			printf("%d %d\n",y[st2[i]],x[st2[i]]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Getchar() (P1==P2&&(P2=(P1=BUF)+fread(BUF,1,1<<21,stdin),P1==P2)?EOF:*P1++)
char BUF[1<<21],*P1=BUF,*P2=BUF;
inline int read()
{
	int res=0,f=1;
	char ch=Getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=Getchar();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+ch-48,ch=Getchar();
	return res*f;
}
const int N=51;
int n,m,x[N],y[N],st1[N],l1,l2;
int r[N],du[N];
bool o;
bool cmp1(int a,int b){return x[a]<x[b];}
int mp[N][N],id[N],res;
bool b[N],use[N];
void dfs(int now,int val)
{
	if(id[now]!=val&&id[now]!=0)
	{
		o=true;
		return;
	}
	if(b[now])return;
	b[now]=true;
	id[now]=val;
	for(int i=1;i<=n;i++)
		if(mp[now][i])
			dfs(i,val);
}
int main()
{
	n=read();m=read();
	if(m>n)
	{
		printf("NO\n");
		return 0;
	}
	for(int i=1,x,y;i<=m;i++)
	{
		x=read();y=read();
		if(mp[x][y]||x==y)o=true;
		mp[x][y]=mp[y][x]=true;
		du[x]++;
		du[y]++;
	}
	if(o&&n>1)
	{
		printf("NO\n");
		return 0;
	}
	o=false;
	l1=1;
	for(int i=1;i<=n;i++)
	{
		if(du[i]==1)
		{
			res++;
			if(id[i]==0)
			dfs(i,i);
		}
	}
	if(o)
	{
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	printf("%d\n",res/2);
	for(int i=1;i<=n;i++)
	{
		if(du[i]==1&&!use[i])
		{
			use[i]=true;
			for(int j=i+1;j<=n;j++)
				if(du[j]==1&&id[i]!=id[j]&&!use[j])
				{
					use[j]=true;
					printf("%d %d\n",i,j);
					break;
				}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Getchar() (P1==P2&&(P2=(P1=BUF)+fread(BUF,1,1<<21,stdin),P1==P2)?EOF:*P1++)
char BUF[1<<21],*P1=BUF,*P2=BUF;
inline int read()
{
	int res=0,f=1;
	char ch=Getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=Getchar();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+ch-48,ch=Getchar();
	return res*f;
}
const int N=51;
int n,m,x[N],y[N],st1[N],l1,l2;
int r[N],du[N];
bool cmp1(int a,int b)
{
	return x[a]<x[b];
}
int main()
{
	n=read();m=read();
	if(m>n)
	{
		printf("NO\n");
		return 0;
	}
	for(int i=1,x,y;i<=m;i++)
	{
		x=read();y=read();
		if(r[x]!=y&&r[x]!=0)
		{
			printf("NO\n");
			return 0;
		}
		du[y]++;
		r[x]=y;
	}
	l1=1;
	for(int i=1;i<=n;i++)
	{
		if(du[i]==0)
		{
			++l2;
			y[l2]=i;
			int now=i;
			while(r[now])now=r[now];
			l1++;
			x[l1]=now;
		}
	}
	x[1]=x[l1];
	l1--;
//	for(int i=1;i<=l1;i++)
//		printf("%d %d\n",x[i],y[i]);
	for(int i=1;i<=l1;i++)
		if(x[i]>y[i])swap(x[i],y[i]);
	for(int i=1;i<=l1;i++)st1[i]=i;
	sort(st1+1,st1+l1+1,cmp1);
	printf("YES\n");
	printf("%d\n",l1);
	for(int i=1;i<=l1;i++)
	{
		printf("%d %d\n",x[st1[i]],y[st1[i]]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Getchar() (P1==P2&&(P2=(P1=BUF)+fread(BUF,1,1<<21,stdin),P1==P2)?EOF:*P1++)
char BUF[1<<21],*P1=BUF,*P2=BUF;
inline int read()
{
	int res=0,f=1;
	char ch=Getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=Getchar();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+ch-48,ch=Getchar();
	return res*f;
}
const int N=51;
int n,m,x[N],y[N],st[N],ans,l1,l2;
int du[N];
bool o;
bool cmp1(int a,int b){return x[a]<x[b];}
int mp[N][N],id[N],res;
bool b[N],use[N];
void dfs(int now,int val)
{
	if(id[now]!=val&&id[now]!=0)
	{
		o=true;
		return;
	}
	if(b[now])return;
	b[now]=true;
	id[now]=val;
	for(int i=1;i<=n;i++)
		if(mp[now][i])
			dfs(i,val);
}
int main()
{
	n=read();m=read();
	if(m>n)
	{
		printf("NO\n");
		return 0;
	}
	for(int i=1,x,y;i<=m;i++)
	{
		x=read();y=read();
		if(mp[x][y]&&n>2)
		{
			printf("NO\n");
			return 0;
		}
		if(x==y)o=true;
		mp[x][y]=mp[y][x]=1;
		du[x]++;
		du[y]++;
	}
	if(o&&n>1)
	{
		printf("NO\n");
		return 0;
	}
	o=false;
	l1=1;
	for(int i=1;i<=n;i++)
	{
		if(du[i]==1)
		{
			if(id[i]==0)
			dfs(i,i);
		}
		if(du[i]<=1)res+=2-du[i];
		else
		{
			printf("NO\n");
			return 0;
		}
	}
	if(o)
	{
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	printf("%d\n",res/2);
	if(res/2==1)
	{
		for(int i=1;i<=n;i++)
			if(du[i]<=1)
				printf("%d ",i);
		if(n==1)printf("1");
		return 0;
	}
	for(int i=1;i<=n;i++)
		if(du[i]<=1)
		{

			use[i]=true;
			for(int j=1;j<=n;j++)
				if(du[j]<=1&&(id[i]!=id[j]||(id[i]==0&&id[j]==0))&&i!=j)
				{
//printf("i=%d %d\n",i,j);
					du[i]++;
					du[j]++;
					x[++ans]=min(i,j);
					y[ans]=max(i,j);
					break;
				}
		}
	for(int i=1;i<=res/2;i++)st[i]=i;
	sort(st+1,st+res/2+1,cmp1);
	for(int i=1;i<=res/2;i++)
		printf("%d %d\n",x[st[i]],y[st[i]]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Getchar() (P1==P2&&(P2=(P1=BUF)+fread(BUF,1,1<<21,stdin),P1==P2)?EOF:*P1++)
char BUF[1<<21],*P1=BUF,*P2=BUF;
inline int read()
{
	int res=0,f=1;
	char ch=Getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=Getchar();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+ch-48,ch=Getchar();
	return res*f;
}
const int N=51;
int n,m,x[N],y[N],st[N],ans,l1,l2;
int du[N];
bool o;
bool cmp1(int a,int b){return x[a]<x[b];}
int mp[N][N],id[N],res;
bool b[N],use[N];
void dfs(int now,int val)
{
	if(id[now]!=val&&id[now]!=0)
	{
		o=true;
		return;
	}
	if(b[now])return;
	b[now]=true;
	id[now]=val;
	for(int i=1;i<=n;i++)
		if(mp[now][i])
			dfs(i,val);
}
int main()
{
	n=read();m=read();
	if(m>n)
	{
		printf("NO\n");
		return 0;
	}
	for(int i=1,x,y;i<=m;i++)
	{
		x=read();y=read();
		if(mp[x][y]||x==y)o=true;
		mp[x][y]=mp[y][x]=1;
		du[x]++;
		du[y]++;
	}
	if(o&&n>1)
	{
		printf("NO\n");
		return 0;
	}
	o=false;
	l1=1;
	for(int i=1;i<=n;i++)
	{
		if(du[i]==1)
		{
			if(id[i]==0)
			dfs(i,i);
		}
		if(du[i]<=1)res+=2-du[i];
	}
	if(o)
	{
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	printf("%d\n",res/2);
	if(res/2==1)
	{
		for(int i=1;i<=n;i++)
			if(du[i]<=1)
				printf("%d ",i);
		return 0;
	}
	for(int i=1;i<=n;i++)
		if(du[i]<=1)
		{

			use[i]=true;
			for(int j=1;j<=n;j++)
				if(du[j]<=1&&(id[i]!=id[j]||(id[i]==0&&id[j]==0))&&i!=j)
				{
//printf("i=%d %d\n",i,j);
					du[i]++;
					du[j]++;
					x[++ans]=min(i,j);
					y[ans]=max(i,j);
					break;
				}
		}
	for(int i=1;i<=res/2;i++)st[i]=i;
	sort(st+1,st+res/2+1,cmp1);
	for(int i=1;i<=res/2;i++)
		printf("%d %d\n",x[st[i]],y[st[i]]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Getchar() (P1==P2&&(P2=(P1=BUF)+fread(BUF,1,1<<21,stdin),P1==P2)?EOF:*P1++)
char BUF[1<<21],*P1=BUF,*P2=BUF;
inline int read()
{
	int res=0,f=1;
	char ch=Getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=Getchar();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+ch-48,ch=Getchar();
	return res*f;
}
const int N=50+5;
int fa[N],du[N],n,m;
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
pair<int,int> ans[N];
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		++du[x];++du[y];
		fa[find(x)]=find(y);
	}
	for(int i=1;i<=n;i++)
		if(du[i]>2)
		{
			puts("NO");
			return 0;
		}
	int top=0;
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
			if(find(i)!=find(j)&&du[i]<2&&du[j]<2)
			{
				ans[++top]=make_pair(i,j);
				++du[i];++du[j];
				fa[find(i)]=find(j);
			}
	if(m+top==n-1)
	{
		++top;
		for(int i=1;i<=n;i++)
			while(du[i]<2)
			{
				++du[i];
				if(!ans[top].first)ans[top].first=i;
				else ans[top].second=i;
			}
	}
	for(int i=1;i<=n;i++)
	if(find(i)!=find(1))
	{
		puts("NO");
		return 0;
	}
	puts("YES");
	printf("%d\n",top);
	for(int i=1;i<=top;i++)printf("%d %d\n",ans[i].first,ans[i].second);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Getchar() (P1==P2&&(P2=(P1=BUF)+fread(BUF,1,1<<21,stdin),P1==P2)?EOF:*P1++)
char BUF[1<<21],*P1=BUF,*P2=BUF;
inline int read()
{
	int res=0,f=1;
	char ch=Getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=Getchar();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+ch-48,ch=Getchar();
	return res*f;
}
const int N=51;
int n,m,x[N],y[N],st1[N],st2[N];
int r[N],du[N];
bool cmp1(int a,int b)
{
	return x[a]<x[b];
}
bool cmp2(int a,int b)
{
	return y[a]<y[b];
}
int main()
{
	n=read();m=read();
	for(int i=1,x,y;i<=m;i++)
	{
		x=read();y=read();
		if(r[x]!=y&&r[x]!=0)
		{
			printf("NO\n");
			return 0;
		}
		du[y]++;
		r[x]=y;
	}
	x[0]=1;
	for(int i=1;i<=n;i++)
	{
		if(du[i]==0)
		{
			++y[0];
			y[y[0]]=i;
			int now=i;
			while(r[now])now=r[now];
			x[0]++;
			x[x[0]]=now;
		}
	}
	x[1]=x[x[0]];
	x[0]--;
	for(int i=1;i<=x[0];i++)st1[i]=st2[i]=i;
	sort(st1+1,st1+x[0]+1,cmp1);
	sort(st2+1,st2+x[0]+1,cmp2);
	printf("YES\n");
	printf("%d\n",x[0]);
	if(x[1]<y[1])
	{
		for(int i=1;i<=x[0];i++)
			printf("%d %d\n",x[i],y[i]);
	}
	else if(x[1]>y[1])
	{
		for(int i=1;i<=x[0];i++)
			printf("%d %d\n",y[i],x[i]);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Getchar() (P1==P2&&(P2=(P1=BUF)+fread(BUF,1,1<<21,stdin),P1==P2)?EOF:*P1++)
char BUF[1<<21],*P1=BUF,*P2=BUF;
inline int read()
{
	int res=0,f=1;
	char ch=Getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=Getchar();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+ch-48,ch=Getchar();
	return res*f;
}
const int N=51;
int n,m,x[N],y[N],st[N],ans,l1,l2;
int du[N];
bool o;
bool cmp1(int a,int b){return x[a]<x[b];}
int mp[N][N],id[N],res;
bool b[N],use[N];
void dfs(int now,int val)
{
	if(id[now]!=val&&id[now]!=0)
	{
		o=true;
		return;
	}
	if(b[now])return;
	b[now]=true;
	id[now]=val;
	for(int i=1;i<=n;i++)
		if(mp[now][i])
			dfs(i,val);
}
int main()
{
	n=read();m=read();
	if(m>n)
	{
		printf("NO\n");
		return 0;
	}
	for(int i=1,x,y;i<=m;i++)
	{
		x=read();y=read();
		if(mp[x][y]&&n>2)
		{
			printf("NO\n");
			return 0;
		}
		if(x==y)o=true;
		mp[x][y]=mp[y][x]=1;
		du[x]++;
		du[y]++;
	}
	if(o&&n>1)
	{
		printf("NO\n");
		return 0;
	}
	o=false;
	l1=1;
	for(int i=1;i<=n;i++)
	{
		if(du[i]==1)
		{
			if(id[i]==0)
			dfs(i,i);
		}
		if(du[i]<=1)res+=2-du[i];
	}
	if(o)
	{
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	printf("%d\n",res/2);
	if(res/2==1)
	{
		for(int i=1;i<=n;i++)
			if(du[i]<=1)
				printf("%d ",i);
		if(n==1)printf("1");
		return 0;
	}
	for(int i=1;i<=n;i++)
		if(du[i]<=1)
		{

			use[i]=true;
			for(int j=1;j<=n;j++)
				if(du[j]<=1&&(id[i]!=id[j]||(id[i]==0&&id[j]==0))&&i!=j)
				{
//printf("i=%d %d\n",i,j);
					du[i]++;
					du[j]++;
					x[++ans]=min(i,j);
					y[ans]=max(i,j);
					break;
				}
		}
	for(int i=1;i<=res/2;i++)st[i]=i;
	sort(st+1,st+res/2+1,cmp1);
	for(int i=1;i<=res/2;i++)
		printf("%d %d\n",x[st[i]],y[st[i]]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Getchar() (P1==P2&&(P2=(P1=BUF)+fread(BUF,1,1<<21,stdin),P1==P2)?EOF:*P1++)
char BUF[1<<21],*P1=BUF,*P2=BUF;
inline int read()
{
	int res=0,f=1;
	char ch=Getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=Getchar();}
	while(ch>='0'&&ch<='9')res=(res<<3)+(res<<1)+ch-48,ch=Getchar();
	return res*f;
}
const int N=51;
int n,m,x[N],y[N],st[N],ans,l1,l2;
int du[N];
bool o;
bool cmp1(int a,int b){return x[a]<x[b];}
int mp[N][N],id[N],res;
bool b[N],use[N];
void dfs(int now,int val)
{
	if(id[now]!=val&&id[now]!=0)
	{
		o=true;
		return;
	}
	if(b[now])return;
	b[now]=true;
	id[now]=val;
	for(int i=1;i<=n;i++)
		if(mp[now][i])
			dfs(i,val);
}
int main()
{
	n=read();m=read();
	if(m>n)
	{
		printf("NO\n");
		return 0;
	}
	for(int i=1,x,y;i<=m;i++)
	{
		x=read();y=read();
		if(mp[x][y]&&n>2)
		{
			printf("NO\n");
			return 0;
		}
		if(x==y)o=true;
		mp[x][y]=mp[y][x]=1;
		du[x]++;
		du[y]++;
	}
	if(o&&n>1)
	{
		printf("NO\n");
		return 0;
	}
	o=false;
	l1=1;
	for(int i=1;i<=n;i++)
	{
		if(du[i]==1)
		{
			if(id[i]==0)
			dfs(i,i);
		}
		if(du[i]<=1)res+=2-du[i];
	}
	if(o)
	{
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	printf("%d\n",res/2);
	if(res/2==1)
	{
		for(int i=1;i<=n;i++)
			if(du[i]<=1)
				printf("%d ",i);
		return 0;
	}
	for(int i=1;i<=n;i++)
		if(du[i]<=1)
		{

			use[i]=true;
			for(int j=1;j<=n;j++)
				if(du[j]<=1&&(id[i]!=id[j]||(id[i]==0&&id[j]==0))&&i!=j)
				{
//printf("i=%d %d\n",i,j);
					du[i]++;
					du[j]++;
					x[++ans]=min(i,j);
					y[ans]=max(i,j);
					break;
				}
		}
	for(int i=1;i<=res/2;i++)st[i]=i;
	sort(st+1,st+res/2+1,cmp1);
	for(int i=1;i<=res/2;i++)
		printf("%d %d\n",x[st[i]],y[st[i]]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,fa[105],du[55],ans[55][2];
bool e[55][55];
int findSet(int x){
	return fa[x]==x?x:fa[x]=findSet(fa[x]);
}
int main(){
	scanf("%d %d",&n,&m);
	if(n<m){
		puts("NO");
		return 0;
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		e[u][v]=e[v][u]=1;
		du[u]++,du[v]++;
		if(max(du[u],du[v])>2){
			puts("NO");
			return 0;
		}
		fa[findSet(u)]=findSet(v);
	}
	int num=0;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			if(findSet(i)!=findSet(j)&&max(du[i],du[j])<2){
				num++;
				ans[num][0]=i,ans[num][1]=j;
				du[i]++,du[j]++;
				fa[findSet(i)]=findSet(j);
			}
		}
	}
	if(m+num==n-1){
		num++;
		for(int i=1;i<=n;i++){
			while(du[i]<2){
				du[i]++;
				if(!ans[num][0])ans[num][0]=i;
				else ans[num][1]=i;
			}
		}
	}
	for(int i=1;i<=n;i++)
		if(findSet(i)!=findSet(1)){
			puts("NO");
			return 0;
		}
	puts("YES");
	printf("%d\n",num);
	for(int i=1;i<=num;i++)
		printf("%d %d\n",ans[num][0],ans[num][1]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,fa[105],du[55],ans[55][3];
int findSet(int x){
	return fa[x]==x?x:fa[x]=findSet(fa[x]);
}
int main(){
	scanf("%d %d",&n,&m);
	if(n<m){
		puts("NO");
		return 0;
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		du[u]++,du[v]++;
		if(du[u]>2||du[v]>2){
			puts("NO");
			return 0;
		}
		fa[findSet(u)]=fa[findSet(v)];
	}
	int num=0;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			if(findSet(i)!=findSet(j)&&du[i]<2&&du[j]<2){
				num++;
				ans[num][0]=i,ans[num][1]=j;
				du[i]++,du[j]++;
				fa[findSet(i)]=findSet(j);
			}
		}
	}
	if(m+num==n-1){
		num++;
		for(int i=1;i<=n;i++){
			while(du[i]<2){
				du[i]++;
				if(!ans[num][0])ans[num][0]=i;
				else ans[num][1]=i;
			}
		}
	}
	for(int i=1;i<=n;i++)
		if(findSet(i)!=findSet(1)){
			puts("NO");
			return 0;
		}
	puts("YES");
	printf("%d\n",num);
	for(int i=1;i<=num;i++)
		printf("%d %d\n",ans[i][0],ans[i][1]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,fa[105],du[55],ans[55][2];
int findSet(int x){
	return fa[x]==x?x:fa[x]=findSet(fa[x]);
}
int main(){
	scanf("%d %d",&n,&m);
	if(n<m){
		puts("NO");
		return 0;
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		du[u]++,du[v]++;
		if(du[u]>2||du[v]?>2){
			puts("NO");
			return 0;
		}
		fa[findSet(u)]=fa[findSet(v)];
	}
	int num=0;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			if(findSet(i)!=findSet(j)&&du[i]<2&&du[j]<2){
				num++;
				ans[num][0]=i,ans[num][1]=j;
				du[i]++,du[j]++;
				fa[findSet(i)]=findSet(j);
			}
		}
	}
	if(m+num==n-1){
		num++;
		for(int i=1;i<=n;i++){
			while(du[i]<2){
				du[i]++;
				if(!ans[num][0])ans[num][0]=i;
				else ans[num][1]=i;
			}
		}
	}
	for(int i=1;i<=n;i++)
		if(findSet(i)!=findSet(1)){
			puts("NO");
			return 0;
		}
	puts("YES");
	printf("%d\n",num);
	for(int i=1;i<=num;i++)
		printf("%d %d\n",ans[num][0],ans[num][1]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,fa[105],du[55],ans[55][2];
bool e[55][55];
int findSet(int x){
	return fa[x]==x?x:fa[x]=findSet(fa[x]);
}
int main(){
	scanf("%d %d",&n,&m);
	if(n<m){
		puts("NO");
		return 0;
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		e[u][v]=e[v][u]=1;
		du[u]++,du[v]++;
		if(max(du[u],du[v])>2){
			puts("NO");
			return 0;
		}
		fa[findSet(u)]=findSet(v);
	}
	int num=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(findSet(i)!=findSet(j)&&max(du[i],du[j])<2){
				num++;
				ans[num][0]=i,ans[num][1]=j;
				du[i]++,du[j]++;
				fa[findSet(i)]=findSet(j);
			}
		}
	}
	if(m+num==n-1){
		num++;
		for(int i=1;i<=n;i++){
			while(du[i]<2){
				du[i]++;
				if(!ans[num][0])ans[num][0]=i;
				else ans[num][1]=i;
			}
		}
	}
	for(int i=2;i<=n;i++)
		if(findSet(i)!=findSet(1)){
			puts("NO");
			return 0;
		}
	puts("YES");
	printf("%d\n",num);
	for(int i=1;i<=num;i++)
		printf("%d %d\n",ans[num][0],ans[num][1]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,fa[105],du[55],ans[55][2];
int findSet(int x){
	return fa[x]==x?x:fa[x]=findSet(fa[x]);
}
int main(){
	scanf("%d %d",&n,&m);
	if(n<m){
		puts("NO");
		return 0;
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		du[u]++,du[v]++;
		if(du[u]>2||du[v]>2){
			puts("NO");
			return 0;
		}
		fa[findSet(u)]=fa[findSet(v)];
	}
	int num=0;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			if(findSet(i)!=findSet(j)&&du[i]<2&&du[j]<2){
				num++;
				ans[num][0]=i,ans[num][1]=j;
				du[i]++,du[j]++;
				fa[findSet(i)]=findSet(j);
			}
		}
	}
	if(m+num==n-1){
		num++;
		for(int i=1;i<=n;i++){
			while(du[i]<2){
				du[i]++;
				if(!ans[num][0])ans[num][0]=i;
				else ans[num][1]=i;
			}
		}
	}
	for(int i=1;i<=n;i++)
		if(findSet(i)!=findSet(1)){
			puts("NO");
			return 0;
		}
	puts("YES");
	printf("%d\n",num);
	for(int i=1;i<=num;i++)
		printf("%d %d\n",ans[num][0],ans[num][1]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
int fa[55],e[55][55];//fa�����жϻ���e��ʾ��û�б�
int deg[55];//��ʾ����
pair<int,int> ans[55];//��ans��ʾ�������ıߣ�pair���������
int findfather(int x){//�Ұְ֣���
    return fa[x]==x?x:fa[x]=findfather(fa[x]);
}
int main(){
    ios::sync_with_stdio(false);//�Ż�����
    cin>>n>>m;
    if(n<m){
        cout<<"NO"<<endl;//���m��n����Ȼ����
        return 0;
    }
    for(int i=1;i<=n;i++) fa[i]=i;//���¸��ڵ�

    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        e[a][b]=e[b][a]=1;
        deg[a]++;
        deg[b]++;
        if(deg[a]>2||deg[b]>2){
            cout<<"NO"<<endl;//�����ʱ����ж�
                             //����ȳ�����2���϶����ܳ�һ����
            return 0;
        }
        fa[findfather(a)]=fa[findfather(b)];
    }
    int num=0;
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j++){
            if(findfather(i)!=findfather(j)&&deg[i]<2&&deg[j]<2){
                num++;//ע��num
                ans[num]=make_pair(i,j);
                deg[i]++;
                deg[j]++;
                fa[findfather(i)]=findfather(j);
            }
        }
    }
    if(m+num==n-1){//���һ�������û�к͵�һ����������
        num++;
        for(int i=1;i<=n;i++){
            while(deg[i]<2) { //����Ҫдwhile ���ֻ�������� �ᱻhack��
                deg[i]++;
                if(!ans[num].first) ans[num].first=i;
                else ans[num].second=i;
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(findfather(i)!=findfather(1)){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl<<num<<endl;
    for(int i=1;i<=num;i++){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
    return 0;
}


/***
 * @Author: YaleXin
 * @Email: 181303209@yzu.edu.cn
 */
#include <iostream>
using namespace std;
// 帮派
int parent[51];
// 临界点个数
int adjNums[51];
int getParent(int son) {
    int sonParent = parent[son];
    if (sonParent != parent[sonParent]) parent[son] = getParent(sonParent);
    return parent[son];
}
int main() {
    int n, m, u, v, uParent, vParent;
    // 记录是否有环
    bool ok = true;
    cin >> n >> m;
    //特判，只有一个点和0条边；
    if (n == 1 && m == 0) return cout << "YES\n1\n 1 1" << flush, 0;
    for (int i = 0; i <= n; i++) parent[i] = i;
    for (int i = 1; i <= m; i++) {
        cin >> u >> v;
        if (!ok) continue;
        uParent = getParent(u);
        vParent = getParent(v);
        adjNums[u]++;
        adjNums[v]++;
        if (adjNums[u] > 2 || adjNums[v] > 2) {
            ok = false;
            continue;
        }
        // 二者不同 “帮派”
        if (uParent != vParent) parent[vParent] = uParent;
        else  ok = false;
    }
    if (m > n) return cout << "NO" << endl, 0;
    // 如果图中有环， 需要判断有几个“帮派”
    if (!ok){
        int count = 0;
        for(int i = 1;i <= n;i++)if(i == parent[i])count++;
        if(count > 1)return cout << "NO" << endl, 0;
        return cout << "YES\n0" << endl, 0;
    }
    else {
        if (n == m) {
            cout << "YES\n0" << flush;
            return 0;
        }
        cout << "YES\n" << n - m << endl;
        // 先连成一条条直线
        for (u = 1; u <= n; u++) {
            if (adjNums[u] == 2) continue;
            uParent = getParent(u);
            for (v = u + 1; v <= n; v++) {
                vParent = getParent(v);
                if (adjNums[v] == 2 || vParent == uParent) continue;
                cout << u << " " << v << endl;
                parent[vParent] = uParent;
                adjNums[u]++;
                adjNums[v]++;
                if (adjNums[u] > 1) break;
            }
        }
        // 连接最后一条
        u = -1, v = -1;
        for (int i = 1; i <= n; i++)
        if (adjNums[i] == 2)continue;
        else if (u == -1)u = i;
        else{
            v = i;
            break;
        }
        cout<<u<<" "<<v<<flush;
    }
    return 0;
}
/*
5 4
1 3
2 3
3 4
3 5
no

5 2
1 4
2 3
YES
3
1 2
3 5
4 5

3 3
1 2
1 3
2 3
YES
0

4 3
1 2
2 3
2 4
NO

5 0
YES
5
1 2
1 3
2 4
3 5
4 5

6 6
1 2
1 3
4 5
4 6
1 4
3 5
NO

5 4
1 2
1 3
4 5
2 3
NO
*/


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

const int N = 50 + 7, M = 2500 + 7;

int n, m;
int deg[N];
int fa[N], cnt;

int gfa(int x) {
	return fa[x] == x ? x : fa[x] = gfa(fa[x]);
}

int belong(int x, int y) {
	return cnt <= 1 ? 0 : gfa(x) == gfa(y);
}

int main() {
	scanf("%d%d", &n, &m);
	if (m > n) return printf("NO"), 0;
	for (int i = 1; i <= n; ++i)
		fa[i] = i;
	cnt = n;
	for (int i = 1, u, v; i <= m; ++i) {
		scanf("%d%d", &u, &v);
		if (deg[u] == 2 || deg[v] == 2) return printf("NO"), 0;
		if (belong(u, v)) return printf("NO"), 0;
		++deg[u], ++deg[v];
		fa[gfa(u)] = gfa(v);
		--cnt;
	}
	printf("YES\n%d\n", n - m);
	for (int i = 1; i <= n; ++i)
		while (deg[i] < 2)
			for (int j = i + 1; j <= n; ++j)
				if (!belong(i, j) && deg[j] < 2) {
					printf("%d %d\n", i, j),
					++deg[i], ++deg[j];
					fa[gfa(i)] = gfa(j);
					--cnt;
					break;
				}
	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int fa[51],b[51],n,m,h[51][51];
int find(int x)
{
	if(fa[x]==x)return x;
	return fa[x]=find(fa[x]);
}
int main()
{
	scanf("%d%d",&n,&m);
	if(n==1&&m==0)
	{
		printf("YES\n1\n1 1");
		return 0;
	}
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(x==y&&n>1)
		{
			printf("NO");
			return 0;
		}
		if(h[x][y]==1&&n>2)
		{
			printf("NO");
			return 0;
		}
		h[x][y]=1;
		h[y][x]=1;
		b[x]++;
		b[y]++;
		fa[find(x)]=find(y);
	}
	if(m>n)
	{
		printf("NO");
		return 0;
	}
	for(int i=1;i<=n;i++)
	if(b[i]>2)
	{
		printf("NO");
		return 0;
	}
	if(m==n)
	{
		printf("YES\n0");
		return 0;
	}
	printf("YES\n%d\n",n-m);
	for(int i=1;i<=n-m;i++)
	{
		int t1=-1,t2=-1;
		for(int j=1;j<=n;j++)
		{
			if(t1==-1&&b[j]<2){t1=j;continue;}
			if(b[j]<2&&t1>-1&&(find(j)!=find(t1)||i==n-m)){t2=j;break;}
		}
		printf("%d %d\n",t1,t2);
		b[t1]++;b[t2]++;
		fa[find(t1)]=find(t2);
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#define ll long long
#define maxn 105
#define inf 2147483647
#define mod 10003
#define eps 1e-6
#define pi acos(-1.0)
#define de(x) ((x)*(x))
using namespace std;
inline int read(){
    int x=0,f=1; char ch=getchar();
    while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
    return x*f;
}
int deep[maxn],fa[maxn];//deep[]记录度数
int n,m,ans;
struct Node{//记录加边情况
	int u,v;
}e[1100];
inline void init(){for(int i=1;i<=n;i++) fa[i]=i;}
inline int find(int x){
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}
inline void Union(int x,int y){
	int xx=find(x),yy=find(y);
	if(xx!=yy) fa[xx]=yy;
}
inline bool check(){
    for(int i=1;i<=n;i++)
    if(deep[i]<2){
        for(int j=i+1;j<=n;j++)
        if(deep[j]<2&&find(i)!=find(j)){
            Union(i,j);
            e[ans].u=i; e[ans].v=j;
            ans++;
            deep[i]++; deep[j]++;
            break;
        }
        if(deep[i]<2)
        for(int j=i+1;j<=n;j++)
        if(deep[j]<2&&find(i)!=find(j)){
            Union(i,j);
            e[ans].u=i; e[ans].v=j;
            ans++;
            deep[i]++; deep[j]++;
            break;
        }
    }
    int cot=0;
    for(int i=1;i<=n;i++){
        if(deep[i]!=1&&deep[i]!=2) return false;
        if(deep[i]==1) cot++;
    }
    if(cot==2) return true;
    else return false;
}
bool flag,sign;
signed main(){
	n=read(); m=read();
	if(n==1&&m==0) return printf("YES\n1\n1 1"),0;//特判，只有一个点和0条边；
	int tmp=0; flag=sign=false;
	init(); ans=0;
	for(int i=1;i<=m;i++){
		int x=read(),y=read();
		deep[x]++; deep[y]++;
		if(find(x)==find(y)) flag=true;//如果为环，标记为一
		Union(x,y);
	}
	for(int i=1;i<=n;i++) tmp=max(tmp,deep[i]);
	if(tmp>2) return puts("NO"),0;//如果度数>2 ，肯定为0；
	if(flag){/若原图有环
		int t=find(1);
		for(int i=2;i<=n;i++)
		if(t==find(i)&&deep[i]==2) continue;
		else{sign=true; break;}
		if(!sign) return printf("YES\n0"),0;
		else return puts("NO");
	}
	if(check()){
		int p[2],cnt=0;
		for(int i=1;i<=n;i++) if(deep[i]==1) p[cnt++]=i;
		e[ans].u=p[0]; e[ans++].v=p[1];
		puts("YES"); printf("%d\n",ans);
		for(int i=0;i<ans;i++) printf("%d %d\n",e[i].u,e[i].v);
	}
	else return puts("NO"),0;
    return 0;
}


#include<bits/stdc++.h>
#define ps puts("")
#define fi first
#define nd second
#define mset(x) memset((x), 0, sizeof (x))
#define mk make_pair
#define sqr(x) ((x)*(x))
#define pii pair<int,int>
#define lch (o<<1)
#define rch (o<<1|1)
using namespace std;
typedef long long ll;
ll read() {ll x = 0;char f = 1, ch = getchar();while(ch < '0' || ch > '9') {if(ch == '-')f = -1;
ch = getchar();}while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0';ch = getchar();}return x * f;}
void write(ll x) {if(x < 0) x = -x, putchar('-');if(x > 9) write(x / 10);putchar(x % 10 + '0');}
inline void writeln(ll x) {write(x);puts("");}
const int N = 110000, M = 400000;
int n, m;
int fa[N];
int Find(int x) {
	return fa[x] == x ?x : fa[x] = Find(fa[x]);
}
int p = 0, d[N],x[N], y[N], tot;
int main() {
	n = read(), m = read();
	for(int i = 1; i <= n; ++i)
		fa[i] = i;
	for(int i = 1; i <= m; ++i) {
		int x = read(), y = read();
		fa[Find(x)] = Find(y);
		++d[x], ++d[y];
	}
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			if(d[i] <= 1 && d[j] <= 1 && Find(i) != Find(j))
				++d[i], ++d[j], fa[Find(i)] = Find(j), x[++tot] = i, y[tot] = j;
	if(m + tot == n - 1) {
		++tot;
		for(int i = 1; i <= n; ++i)
			if(d[i] <= 1) {
				++d[i];
				x[tot] = i;
				for(int j = 1; j <= n; ++j)
					if(d[j] <= 1) {
						y[tot] = j;
						++d[j];
						fa[Find(i)] = Find(j);
						break;
					}
				break;
			}
	}
	for(int i = 1; i <= n; ++i)
		if(Find(i) != Find(1) || d[i] <= 1 || m + tot > n) {
			puts("NO");return 0;
		}
	puts("YES");
	writeln(tot);
	for(int i = 1; i <= tot; ++i)
		printf("%d %d\n", x[i], y[i]);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
vector<pair<int,int> > ans;
int deg[55];
int par[55];
int Rank[55];
void init(int n){
    for(int i=1;i<=n;i++){
        par[i]=i;Rank[i]=0;
    }
}
int Find(int x){
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=Find(par[x]);
    }
}
void unite(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y)return;
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
int main(){
    int n,m,x,y,deg1=0,deg0=0,i,j;
    scanf("%d%d",&n,&m);
    init(n);
    for(i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        if(x==y) return puts("NO"),0;
        deg[x]++;
        deg[y]++;
    }
    for(i=1;i<=n;i++){
        if(deg[i]>2)
            break;
        if(deg[i]==1){
            deg1++;
        }
        if(deg[i]==0){
            deg0++;
        }
    }
    if(i<=n){
        printf("NO\n");
        return 0;
    }
    if(deg1==0&&deg0==0){
        printf("YES\n0\n");
        return 0;
    }
    if(deg1==0&&deg0&&m){
        printf("NO\n");
        return 0;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(deg[i]<=1&&deg[j]<=1&&Find(i)!=Find(j)){
                deg[i]++;
                deg[j]++;
                ans.push_back(make_pair(i,j));
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(deg[i]==1){
            q.push(i);
        }
    }
    while(!q.empty()){
        int a,b;
        a=q.top();q.pop();
        b=q.top();q.pop();
        ans.push_back(make_pair(a,b));
    }
    sort(ans.begin(),ans.end());
    printf("YES\n");
    printf("%d\n",ans.size());
    for(i=0;i<ans.size();i++){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
vector<pair<int,int> > ans;
int deg[55];
int par[55];
int Rank[55];
void init(int n){
    for(int i=1;i<=n;i++){
        par[i]=i;Rank[i]=0;
    }
}
int Find(int x){
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=Find(par[x]);
    }
}
void unite(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y)return;
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
int main(){
    int n,m,x,y,deg1=0,deg0=0,deg2=0,i,j;
    scanf("%d%d",&n,&m);
    init(n);
    for(i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        deg[x]++;
        deg[y]++;
        if(x==y)
            deg2++;
    }
    for(i=1;i<=n;i++){
        if(deg[i]>2)
            break;
        if(deg[i]==1){
            deg1++;
        }
        if(deg[i]==0){
            deg0++;
        }
    }
    if(i<=n||deg2>1){
        printf("NO\n");
        return 0;
    }
    if(deg1==0&&deg0==0){
        printf("YES\n0\n");
        return 0;
    }
    if(deg1==0&&deg0&&m){
        printf("NO\n");
        return 0;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(deg[i]<=1&&deg[j]<=1&&Find(i)!=Find(j)){
                deg[i]++;
                deg[j]++;
                ans.push_back(make_pair(i,j));
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(deg[i]==1){
            q.push(i);
        }
    }
    while(!q.empty()){
        int a,b;
        a=q.top();q.pop();
        b=q.top();q.pop();
        ans.push_back(make_pair(a,b));
    }
    sort(ans.begin(),ans.end());
    printf("YES\n");
    printf("%d\n",ans.size());
    for(i=0;i<ans.size();i++){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
vector<pair<int,int> > ans;
int deg[55];
int par[55];
int Rank[55];
void init(int n){
    for(int i=1;i<=n;i++){
        par[i]=i;Rank[i]=0;
    }
}
int Find(int x){
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=Find(par[x]);
    }
}
void unite(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y)return;
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
int main(){
    int n,m,x,y,deg1=0,deg0=0,deg2=0,i,j;
    scanf("%d%d",&n,&m);
    init(n);
    if(n==1&&!m){
        printf("YES\n1\n1 1\n");
        return 0;
    }
    for(i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        deg[x]++;
        deg[y]++;
        if(x==y)
            deg2++;
        unite(x,y);
    }
    for(i=1;i<=n;i++){
        if(deg[i]>2)
            break;
        if(deg[i]==1){
            deg1++;
        }
        if(deg[i]==0){
            deg0++;
        }
    }
    if(deg2==1&&n>1){
        printf("NO\n");
        return 0;
    }
    if(i<=n||deg2>1){
        printf("NO\n");
        return 0;
    }
    if(deg1==0&&deg0==0){
        printf("YES\n0\n");
        return 0;
    }
    if(deg1==0&&deg0&&m){
        printf("NO\n");
        return 0;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(deg[i]<=1&&deg[j]<=1&&Find(i)!=Find(j)){
                deg[i]++;
                deg[j]++;
                ans.push_back(make_pair(i,j));
                unite(i,j);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(deg[i]==1){
            q.push(i);
        }
    }
    while(!q.empty()){
        int a,b;
        a=q.top();q.pop();
        b=q.top();q.pop();
        ans.push_back(make_pair(a,b));
        unite(a,b);
    }
    sort(ans.begin(),ans.end());
    printf("YES\n");
    printf("%d\n",ans.size());
    for(i=0;i<ans.size();i++){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
vector<pair<int,int> > ans;
int deg[55];
int par[55];
int Rank[55];
void init(int n){
    for(int i=1;i<=n;i++){
        par[i]=i;Rank[i]=0;
    }
}
int Find(int x){
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=Find(par[x]);
    }
}
void unite(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y)return;
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
int main(){
    int n,m,x,y,deg1=0,deg0=0,deg2=0,i,j;
    scanf("%d%d",&n,&m);
    init(n);
    for(i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        deg[x]++;
        deg[y]++;
        if(x==y)
            deg2++;
    }
    for(i=1;i<=n;i++){
        if(deg[i]>2)
            break;
        if(deg[i]==1){
            deg1++;
        }
        if(deg[i]==0){
            deg0++;
        }
    }
    if(deg2==1&&n>1){
        printf("NO\n");
        return 0;
    }
    if(i<=n||deg2>1){
        printf("NO\n");
        return 0;
    }
    if(deg1==0&&deg0==0){
        printf("YES\n0\n");
        return 0;
    }
    if(deg1==0&&deg0&&m){
        printf("NO\n");
        return 0;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(deg[i]<=1&&deg[j]<=1&&Find(i)!=Find(j)){
                deg[i]++;
                deg[j]++;
                ans.push_back(make_pair(i,j));
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(deg[i]==1){
            q.push(i);
        }
    }
    while(!q.empty()){
        int a,b;
        a=q.top();q.pop();
        b=q.top();q.pop();
        ans.push_back(make_pair(a,b));
    }
    sort(ans.begin(),ans.end());
    printf("YES\n");
    printf("%d\n",ans.size());
    for(i=0;i<ans.size();i++){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
vector<pair<int,int> > ans;
int deg[55];
int par[55];
int Rank[55];
void init(int n){
    for(int i=1;i<=n;i++){
        par[i]=i;Rank[i]=0;
    }
}
int Find(int x){
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=Find(par[x]);
    }
}
void unite(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y)return;
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
int main(){
    int n,m,x,y,deg1=0,deg0=0,i,j;
    scanf("%d%d",&n,&m);
    init(n);
    for(i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        deg[x]++;
        deg[y]++;
    }
    for(i=1;i<=n;i++){
        if(deg[i]>2)
            break;
        if(deg[i]==1){
            deg1++;
        }
        if(deg[i]==0){
            deg0++;
        }
    }
    if(i<=n){
        printf("NO\n");
        return 0;
    }
    if(deg1==0&&deg0==0){
        printf("YES\n0\n");
        return 0;
    }
    if(deg1==0&&deg0){
        printf("NO\n");
        return 0;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(deg[i]<=1&&deg[j]<=1&&Find(i)!=Find(j)){
                deg[i]++;
                deg[j]++;
                ans.push_back(make_pair(i,j));
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(deg[i]==1){
            q.push(i);
        }
    }
    while(!q.empty()){
        int a,b;
        a=q.top();q.pop();
        b=q.top();q.pop();
        ans.push_back(make_pair(i,j));
    }
    sort(ans.begin(),ans.end());
    printf("YES\n");
    printf("%d\n",ans.size());
    for(i=0;i<ans.size();i++){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
vector<pair<int,int> > ans;
int deg[55];
int par[55];
int Rank[55];
void init(int n){
    for(int i=1;i<=n;i++){
        par[i]=i;Rank[i]=0;
    }
}
int Find(int x){
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=Find(par[x]);
    }
}
void unite(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y)return;
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
int main(){
    int n,m,x,y,deg1=0,deg0=0,i,j;
    scanf("%d%d",&n,&m);
    init(n);
    for(i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        deg[x]++;
        deg[y]++;
    }
    for(i=1;i<=n;i++){
        if(deg[i]>2)
            break;
        if(deg[i]==1){
            deg1++;
        }
        if(deg[i]==0){
            deg0++;
        }
    }
    if(i<=n){
        printf("NO\n");
        return 0;
    }
    if(deg1==0&&deg0==0){
        printf("YES\n0\n");
        return 0;
    }
    if(deg1==0&&deg0&&m){
        printf("NO\n");
        return 0;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(deg[i]<=1&&deg[j]<=1&&Find(i)!=Find(j)){
                deg[i]++;
                deg[j]++;
                ans.push_back(make_pair(i,j));
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(deg[i]==1){
            q.push(i);
        }
    }
    while(!q.empty()){
        int a,b;
        a=q.top();q.pop();
        b=q.top();q.pop();
        ans.push_back(make_pair(a,b));
    }
    sort(ans.begin(),ans.end());
    printf("YES\n");
    printf("%d\n",ans.size());
    for(i=0;i<ans.size();i++){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
vector<pair<int,int> > ans;
int deg[55];
int par[55];
int Rank[55];
void init(int n){
    for(int i=1;i<=n;i++){
        par[i]=i;Rank[i]=0;
    }
}
int Find(int x){
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=Find(par[x]);
    }
}
void unite(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y)return;
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
int main(){
    int n,m,x,y,deg1=0,deg0=0,deg2=0,i,j;
    scanf("%d%d",&n,&m);
    init(n);
    if(n==1&&!m){
        printf("YES\n1\n1 1\n");
        return 0;
    }
    for(i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        deg[x]++;
        deg[y]++;
        if(x==y)
            deg2++;
    }
    for(i=1;i<=n;i++){
        if(deg[i]>2)
            break;
        if(deg[i]==1){
            deg1++;
        }
        if(deg[i]==0){
            deg0++;
        }
    }
    if(deg2==1&&n>1){
        printf("NO\n");
        return 0;
    }
    if(i<=n||deg2>1){
        printf("NO\n");
        return 0;
    }
    if(deg1==0&&deg0==0){
        printf("YES\n0\n");
        return 0;
    }
    if(deg1==0&&deg0&&m){
        printf("NO\n");
        return 0;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(deg[i]<=1&&deg[j]<=1&&Find(i)!=Find(j)){
                deg[i]++;
                deg[j]++;
                ans.push_back(make_pair(i,j));
                unite(i,j);
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(deg[i]==1){
            q.push(i);
        }
    }
    while(!q.empty()){
        int a,b;
        a=q.top();q.pop();
        b=q.top();q.pop();
        ans.push_back(make_pair(a,b));
        unite(a,b);
    }
    sort(ans.begin(),ans.end());
    printf("YES\n");
    printf("%d\n",ans.size());
    for(i=0;i<ans.size();i++){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
vector<pair<int,int> > ans;
int deg[55];
int par[55];
int Rank[55];
void init(int n){
    for(int i=1;i<=n;i++){
        par[i]=i;Rank[i]=0;
    }
}
int Find(int x){
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=Find(par[x]);
    }
}
void unite(int x,int y){
    x=Find(x);
    y=Find(y);
    if(x==y)return;
    if(Rank[x]<Rank[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(Rank[x]==Rank[y]) Rank[x]++;
    }
}
int main(){
    int n,m,x,y,deg1=0,deg0=0,deg2=0,i,j;
    scanf("%d%d",&n,&m);
    init(n);
    if(n==1&&!m){
        printf("YES\n1\n1 1\n");
        return 0;
    }
    for(i=0;i<m;i++){
        scanf("%d%d",&x,&y);
        deg[x]++;
        deg[y]++;
        if(x==y)
            deg2++;
    }
    for(i=1;i<=n;i++){
        if(deg[i]>2)
            break;
        if(deg[i]==1){
            deg1++;
        }
        if(deg[i]==0){
            deg0++;
        }
    }
    if(deg2==1&&n>1){
        printf("NO\n");
        return 0;
    }
    if(i<=n||deg2>1){
        printf("NO\n");
        return 0;
    }
    if(deg1==0&&deg0==0){
        printf("YES\n0\n");
        return 0;
    }
    if(deg1==0&&deg0&&m){
        printf("NO\n");
        return 0;
    }
    for(i=1;i<=n;i++){
        for(j=i+1;j<=n;j++){
            if(deg[i]<=1&&deg[j]<=1&&Find(i)!=Find(j)){
                deg[i]++;
                deg[j]++;
                ans.push_back(make_pair(i,j));
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(deg[i]==1){
            q.push(i);
        }
    }
    while(!q.empty()){
        int a,b;
        a=q.top();q.pop();
        b=q.top();q.pop();
        ans.push_back(make_pair(a,b));
    }
    sort(ans.begin(),ans.end());
    printf("YES\n");
    printf("%d\n",ans.size());
    for(i=0;i<ans.size();i++){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}