#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define erep(i, x, n) for (int i = x; i<=(int)(n); i++)
#define rep(i, x, n) for(int i = x; i<(int)(n); i++)
#define vi vector<int>
#define vii vector< pair<int, int> >
#define vvi vector< vi >
#define vll vector<long long>
#define vc vector<char>
#define vb vector<bool>
#define vvii vector< vector< pii > >
#define pii pair<int, int>
#define mapii map<int, int>
#define mapsi map<string, int>
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pie  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-9)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string x;
    cin >> x;
    vi vec;
    int temp = 0;
    bool visited[1001] = {};
    rep(i, 0, sz(x))
    {
        if (x[i] != ',') temp = temp*10 + x[i] - 48;
        else
        {
            if (!visited[temp]) vec.push_back(temp), visited[temp] = true;
            temp = 0;
        }
        if (i+1 == sz(x) && temp) if (!visited[temp]) vec.push_back(temp);
    }
    sort(all(vec));
    int prev = 0, cnt = 0, last = vec.back();
    rep(i, 0, sz(vec))
    {
        if (vec[i] >= cnt)
        {
            cout << vec[i];
            if (vec[i] != last)
            {
                int prev = vec[i]+1, hoba = 0;
                while(prev <= 1000 && visited[prev])
                {
                    prev++;
                    hoba++;
                }
                cnt = prev-1;
                if (hoba >= 2) cout << "-";
                else cout << ",";
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define erep(i, x, n) for (int i = x; i<=(int)(n); i++)
#define rep(i, x, n) for(int i = x; i<(int)(n); i++)
#define vi vector<int>
#define vii vector< pair<int, int> >
#define vvi vector< vi >
#define vll vector<long long>
#define vc vector<char>
#define vb vector<bool>
#define vvii vector< vector< pii > >
#define pii pair<int, int>
#define mapii map<int, int>
#define mapsi map<string, int>
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pie  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-9)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string x;
    cin >> x;
    vi vec;
    int temp = 0;
    bool visited[1001] = {};
    rep(i, 0, sz(x))
    {
        if (x[i] != ',') temp = temp*10 + x[i] - 48;
        else
        {
            if (!visited[temp]) vec.push_back(temp), visited[temp] = true;
            temp = 0;
        }
        if (i+1 == sz(x) && temp) if (!visited[temp]) vec.push_back(temp);
    }
    sort(all(vec));
    int prev = 0, cnt = 0, last = vec.back();
    rep(i, 0, sz(vec))
    {
        if (vec[i] >= cnt)
        {
            cout << vec[i];
            if (vec[i] != last)
            {
                int prev = vec[i]+1, hoba = 0;
                while(prev <= 1001 && visited[prev])
                {
                    prev++;
                    hoba++;
                }
                cnt = prev-1;
                if (hoba >= 2) cout << "-";
                else cout << ",";
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool a[10001],cmp;
/// manhhungking1
int main()
{
    freopen("main.inp","r",stdin);
    int x;
    while(~scanf("%d,",&x))a[x]=true;
    int i=1;
    while(i<=1000){
            //cout<<i<<" ";
        int j=i;
        while(a[j]){
            j++;
        }
        if(i==j){i++;continue;}
        j--;
        if(!cmp){
                cmp=true;
            if(i!=j){cout<<i<<"-"<<j;};
            if(i==j && a[i]==true)cout<<i;
        }
        else {
            if(i!=j){cout<<","<<i<<"-"<<j;};
            if(i==j && a[i]==true)cout<<","<<i;
        }
        i=j+1;
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool a[10001],cmp;
/// manhhungking1
int main()
{
    //freopen("main.inp","r",stdin);
    int x;
    while(~scanf("%d,",&x))a[x]=true;
    int i=1;
    while(i<=1000){
            //cout<<i<<" ";
        int j=i;
        while(a[j]){
            j++;
        }
        if(i==j){i++;continue;}
        j--;
        if(!cmp){
                cmp=true;
            if(i!=j){cout<<i<<"-"<<j;};
            if(i==j && a[i]==true)cout<<i;
        }
        else {
            if(i!=j){cout<<","<<i<<"-"<<j;};
            if(i==j && a[i]==true)cout<<","<<i;
        }
        i=j+1;
    }
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <map>
#include <memory>
#include <vector>
#include <stack>
#include <bitset>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <queue>
using namespace std;
char a[100000];
int x=0,q=0,l[100000],r[100000],f[100000];
int main()
{
	gets(a);
	for(int i=0;i<=strlen(a);i++)
	if(a[i]==','||i==strlen(a))
	{
		f[x]=1;
		x=0;
	}
	else x=x*10+a[i]-'0';
	for(int i=1;i<2000;i++)
	if(f[i-1]==0&&f[i])
	{
		l[q]=i;
		r[q]=i;
	}
	else
	if(f[i])
	r[q]++;
	else if(f[i-1])
	q++;
	for(int i=0;i<q;i++)
	{
		if(l[i]==r[i])
		cout<<l[i];
		else
		cout<<l[i]<<"-"<<r[i];
		if(i==q-1)
		cout<<endl;
		else
		cout<<',';
	}
return 0;
}


//begin:9:38
//end:10:00
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <map>
#include <memory>
#include <vector>
#include <stack>
#include <bitset>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <queue>
using namespace std;
int n,tl,ans[1005],cnt;
bool used[1005];
char ch;
int main()
{
	scanf("%d%c",&tl,&ch);
	while(ch==',')
    {
    	used[tl]=true;
    	scanf("%d%c",&tl,&ch);
    }
    used[tl]=true;
    for(int i=1;i<=1000;++i)
    {
    if(used[i])
	{
		for(int j=i;used[j];++j)
		{
			ans[i]=j;
			used[j]=false;
		}
	}
}
cnt=0;
for(int i=1;i<=1000;++i)
{
	if(ans[i])
	{
		++cnt;
		if(cnt !=1)
		printf(",");
		if(ans[i]==i)
		printf("%d",i);
		else
		printf("%d-%d",i,ans[i]);
	}
}
printf("\n");
return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int a;
	vector<int> v;
	cin >>a;
	v.push_back(a);
	while (scanf(",%d",&a));
	{
		v.push_back(a);
	}
	int tap=0,b=0;
	sort (v.begin(),v.end());
	for (int i=0;i<v.size();i++)
	{
		tap++;
		if (i!=v.size()-1 && v[i]!=v[i+1]-1 && v[i]!=v[i+1])
		{
			if (tap==1)
			{
				cout <<v[i];
				b=i+1;
				tap=0;
				if (i!=v.size()-1)
		            cout <<",";
                else
        		    cout <<"\n";
			}
			else
			{
				cout <<v[b]<<"-"<<v[i]<<"90";
				b=i+1;
				tap=0;
				if (i!=v.size()-1)
		            cout <<",";
 			    else
        		    cout <<"\n";
			}
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int a;
	vector<int> v;
	cin >>a;
	v.push_back(a);
	while (scanf(",%d"),&a);
	{
		v.push_back(a);
	}
	int tap=0,b;
	sort (v.begin(),v.end());
	for (int i=0;i<v.size();i++)
	{
		tap++;
		if (i!=v.size()-1 && v[i]!=v[i+1]-1 || i!=v.size()-1 && v[i]!=v[i+1])
		{
			if (tap==1)
			{
				cout <<v[i];
				b=i+1;
				continue;
				tap=0;
				if (i==v.size()-1)
		            cout <<",";
                else
        		{
        		    cout <<"\n";
        	        return 0;
				}
			}
			else
			{
				cout <<v[b]<<"-"<<v[i];
				b=i+1;
				continue;
				tap=0;
				if (i==v.size()-1)
		            cout <<",";
 			    else
        		{
        		    cout <<"\n";
        			return 0;
				}
			}
		}
	}
	return 0;
}


#include <iostream>
#include <map>
using namespace std;
int main()
{
	map<int, int> mp;
	int n;
	cin >>n;
	for (int i=0;i<n;i++)
	{
		int a;
		cin >>a;
		mp[a]++;
	}
	int res=0;
	for (map<int, int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		//if (mp[it]==it) continue;
		if( (*it).first == (*it).second ) continue;
		else if ( (*it).first < (*it).second )
		    res+=(*it).second - (*it).first;
        else
            res+=(*it).second;
	}
	cout <<res;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int a;
	vector<int> v;
    cin >>a;
    v.push_back(a);
    while (scanf(",%d",&a))
    {
    	v.push_back(a);
	}
	int n=v.size();
	int tap=0,b=0;
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
	{
		tap++;
		if (i!=n-1 && v[i]!=v[i+1] && v[i]!=v[i+1]-1)
		{
			if (tap==1)
			{
				cout <<v[i]<<",";
				for(int j=i+1;j<n;j++)
				{
					if (v[j]!=v[i])
					    b=j;
				}
				tap=0;
			}
            else
            {
            	cout <<v[b]<<"-"<<v[i]<<",";
            	for(int j=i+1;j<n;j++)
				{
					if (v[j]!=v[i])
					    b=j;
				}
			}
		}
		if (i==n-1)
		{
			if (v[i]==v[b])
			    cout <<v[i];
            else
                cout <<v[b]<<"-"<<v[i];
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int a;
	vector<int> v;
    cin >>a;
    v.push_back(a);
    while (scanf(",%d",&a))
    {
    	v.push_back(a);
	}
	int n=v.size();
	int tap=0,b=0;
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
	{
		tap++;
		if (i!=n-1 && v[i]!=v[i+1] && v[i]!=v[i+1]-1)
		{
			if (tap==1)
			{
				cout <<v[i]<<",";
				b=i+1;
				tap=0;
			}
            else
            {
            	if (v[b]==v[i])
                    cout <<v[i]<<",";
                else
                    cout <<v[b]<<"-"<<v[i]<<",";
                b=i+1;
                tap=0;
			}
		}
		if (i==n-1)
		{
			if (v[i]==v[b])
			    cout <<v[i];
            else
            {
            	if (v[b]==v[i])
                    cout <<v[i];
                else
                    cout <<v[b]<<"-"<<v[i];
			}
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int a;
	vector<int> v;
	cin >>a;
	v.push_back(a);
	while (scanf(",%d",&a));
	{
		v.push_back(a);
	}
	int tap=0,b=0;
	sort (v.begin(),v.end());
	for (int i=0;i<v.size();i++)
	{
		tap++;
		if (i!=v.size()-1 && v[i]!=v[i+1]-1 && v[i]!=v[i+1])
		{
			if (tap==1)
			{
				cout <<v[i];
				for (int j=i+1;j<v.size();j++)
				{
					if (v[j]!=v[i])
					{
						b=j;
						break;
					}
				}
				tap=0;
				if (i!=v.size()-1)
		            cout <<",";
                else
        		    cout <<"\n";
			}
			else
			{
				cout <<v[b]<<"-"<<v[i];
				for (int j=i+1;j<v.size();j++)
				{
					if (v[j]!=v[i])
					{
					    b=j;
					    break;
	                }
				}
				tap=0;
				if (i!=v.size()-1)
		            cout <<",";
 			    else
        		    cout <<"\n";
			}
		}
		else
		{
			if (v[i]!=v[b])
			    cout <<v[i]<<"\n";
			else
			    cout<<v[b]<<"-"<<v[i]<<"\n";
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
using namespace std;
int n;
int ans=0,total=0,cnt=1,sum=1,l=0,r=0;
int a[100010];
string s;
int main()
{
	//scanf("%d",&n);
	cin>>s;
	int len=s.size();
	//cout<<s<<endl;
	for(int i=len-1;i>=0;i--)
	{
		if(s[i]==',')
		{
			cnt++;
			sum=1;
		}
		else
		{
			a[cnt]+=(s[i]-'0')*sum;
			sum*=10;
		}
	}
	/*for(int i=1;i<=cnt;i++)
		cout<<a[i]<<" ";
	cout<<endl;*/
	sort(a+1,a+cnt+1);
	total=unique(a+1,a+cnt+1)-a-1;
	/*for(int i=1;i<=total;i++)
		cout<<a[i]<<" ";
	cout<<endl;*/
	l=r=a[1];
	for(int i=1;i<total;i++)
	{
		if(a[i+1]-a[i]==1)
		{
			r++;
		}
		else
		{
			if(l==r)printf("%d,",l);
			else printf("%d-%d,",l,r);
			l=r=a[i+1];
		}
	}
	if(l==r)printf("%d",r);
	else printf("%d-%d",l,r);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
using namespace std;
int n;
int ans=0,total=0,cnt=1,sum=1,l=0,r=0;
int a[100010];
string s;
int main()
{
	//scanf("%d",&n);
	cin>>s;
	int len=s.size();
	//cout<<s<<endl;
	for(int i=len-1;i>=0;i--)
	{
		if(s[i]==',')
		{
			cnt++;
			sum=1;
		}
		else
		{
			a[cnt]+=(s[i]-'0')*sum;
			sum*=10;
		}
	}
	/*for(int i=1;i<=cnt;i++)
		cout<<a[i]<<" ";
	cout<<endl;*/
	sort(a+1,a+cnt+1);
	total=unique(a+1,a+cnt+1)-a-1;
	/*for(int i=1;i<=total;i++)
		cout<<a[i]<<" ";
	cout<<endl;*/
	l=r=a[1];
	for(int i=2;i<=total+1;i++)
	{
		if(a[i]-r==1)r++;
		else
		{
			if(l==r)
			{
				if(i==total+1)printf("%d",l);
				else printf("%d,",l);
			}
			else
			{
				if(i==total)printf("%d-%d,",l,r);
				else printf("%d-%d",l,r);
			}
			l=r=a[i];
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int a;
	vector<int> v;
	cin >> a;
	v.push_back(a);
	while(scanf(",%d", &a)) {
		v.push_back(a);
	}

	int tap=0, b=0;
	sort(v.begin(), v.end());
	for (int i=0; i< v.size(); i++) {
		tap++;

		if(i!=v.size()-1 && v[i] != v[i+1]-1 && v[i] != v[i+1]) {
			if(tap==1)
			{
				cout << v[i];
				b=i+1;

				tap=0;
				if(i!=v.size() - 1)
					cout << ",";
				else
					cout << "\n";
			} else {
				if (v[b] == v[i]) cout << v[i];
				else cout << v[b] << "-" << v[i];
				b=i+1;

				tap=0;
				if(i!=v.size()-1)
					cout << "," ;
				else
					cout << "\n" ;

			}
		} else if(i==v.size()-1) {
			if( v[b] == v[i]) cout << v[i];
		 	else cout << v[b] << '-' << v[i];
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int a;
	vector<int> v;
	cin >> a;

	v.push_back(a);

	while(scanf(",%d", &a)) {
		v.push_back(a);
	}

	int tap=0, b=0;

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

	for (int i=0; i< v.size(); i++) {
		tap++;

		if(i!=v.size()-1 && v[i] != v[i+1]-1 && v[i] != v[i+1]) {
			if(tap==1)
			{
				cout << v[i];
				for( int j=i+1; j<v.size(); j++) {
					if(v[j]!=v[i]) {
						b=j;
						break;
					}
				}

				tap=0;
				if(i!=v.size() - 1)
					cout << ",";
				else
					cout << "\n";
			} else {
				if (v[b] == v[i]) cout << v[i];
				else cout << v[b] << "-" << v[i];
				for (int j=i+1; j<v.size(); j++) {
					if(v[j]!=v[i]) {
						b=j;
						break;
					}
				}

				tap=0;
				if(i!=v.size()-1)
					cout << "," ;
				else
					cout << "\n" ;

			}
		} else if(i==v.size()-1) {
			if( v[b] == v[i]) cout << v[i];
		 	else cout << v[b] << '-' << v[i];
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int a;
	vector<int> v;
	cin >> a;

	v.push_back(a);

	while(scanf(",%d", &a)) {
		v.push_back(a);
	}

	int tap=0, b=0;

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

	for (int i=0; i< v.size(); i++) {
		tap++;

		if(i!=v.size()-1 && v[i] != v[i+1]-1 && v[i] != v[i+1]) {
			if(tap==1)
			{
				cout << v[i];
				for( int j=i+1; j<v.size(); j++) {
					if(v[j]!=v[i]) {
						b=j;
						break;
					}
				}

				tap=0;
				if(i!=v.size() - 1)
					cout << ",";
				else
					cout << "\n";
			} else {
				if (v[b] == v[i]) cout << v[i];
				else cout << v[b] << "-" << v[i];
				for (int j=i+1; j<v.size(); j++) {
					if(v[j]!=v[i]) {
						b=j;
						break;
					}
				}

				tap=0;
				if(i!=v.size()-1)
					cout << "," ;
				else
					cout << "\n" ;

			}
		} else if(i==v.size()-1) {
			if(tap==1) {
				cout << v[i];
			} else if (v[i] == v[i-1]) {
				cout << v[i];
			} else {
				cout << v[b] << '-' << v[i];
			}
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int a;
	vector<int> v;
	cin >> a;

	v.push_back(a);

	while(scanf(",%d", &a)) {
		v.push_back(a);
	}

	int tap=0, b=0;

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

	for (int i=0; i< v.size(); i++) {
		tap++;

		if(i!=v.size()-1 && v[i] != v[i+1]-1 && v[i] != v[i+1]) {
			if(tap==1)
			{
				cout << v[i];
				for( int j=i+1; j<v.size(); j++) {
					if(v[j]!=v[i]) {
						b=j;
						break;
					}
				}

				tap=0;
				if(i!=v.size() - 1)
					cout << ",";
				else
					cout << "\n";
			} else {
				if (v[i] == v[i-1]) cout << v[i];
				else cout << v[b] << "-" << v[i];
				for (int j=i+1; j<v.size(); j++) {
					if(v[j]!=v[i]) {
						b=j;
						break;
					}
				}

				tap=0;
				if(i!=v.size()-1)
					cout << "," ;
				else
					cout << "\n" ;

			}
		} else if(i==v.size()-1) {
			if(tap==1) {
				cout << v[i];
			} else if (v[i] == v[i-1]) {
				cout << v[i];
			} else {
				cout << v[b] << '-' << v[i];
			}
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int a;
	vector<int> v;
	cin >> a;

	v.push_back(a);

	while(scanf(",%d", &a)) {
		v.push_back(a);
	}

	int tap=0, b=0;

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

	for (int i=0; i< v.size(); i++) {
		tap++;

		if(i!=v.size()-1 && v[i] != v[i+1]-1 && v[i] != v[i+1]) {
			if(tap==1)
			{
				cout << v[i];
				for( int j=i+1; j<v.size(); j++) {
					if(v[j]!=v[i]) {
						b=j;
						break;
					}
				}

				tap=0;
				if(i!=v.size() - 1)
					cout << ",";
				else
					cout << "\n";
			} else {
				cout << v[b] << "-" << v[i];
				for (int j=i+1; j<v.size(); j++) {
					if(v[j]!=v[i]) {
						b=j;
						break;
					}
				}

				tap=0;
				if(i!=v.size()-1)
					cout << "," ;
				else
					cout << "\n" ;

			}
		} else if(i==v.size()-1) {
			if(tap==1) {
				cout << v[i];
			} else if (v[i] == v[i-1]) {
				cout << v[i];
			} else {
				cout << v[b] << '-' << v[i];
			}
		}
	}
}


/*	THE NAME OF ALLAH	*/
/*
                                       __
   |   |        --          |        /    \
  | | | |      /  |      __ |       |      |
  |  |  |     /---      |   |      |        |
  |     |    |         |    |       |      |
  |     |    |____      |__ |        \ __ /

	   	      _       _
        	/   \   /   \
           /     \ /     \
          |       |       |
           |             |             \
 |\ _ _ _ _ |           |  _ _ _ _ _ _ _\
 |/          |         |                /
              |       |                /
               |     |
      _ _ _     |   |             _ _
    /            | |            /     \
   /              |            |       |
  /                             \     /
 |                               \
 |                                \
 |                                 \
  \                           /     \
   \                         |       |
    \ _ _ _                   \ _ _ /

*/

#include<iostream>
#include<fstream>
#include<algorithm>
#include<set>
#include<string.h>
#include<map>
#include<list>
#include<iomanip>
#include <cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<iterator>
using namespace std;

#define all(v)			((v).begin(),(v).end())
#define sz(v)			((ll)(v).size())
#define clr(v,d)		memset((v),(d),sizeof(v))
#define rep(i,v)		for(ll i = 0 ; i < (ll) sz(v) ; i++ )
#define lp(i,n)			for(ll i = 0 ; i < (ll) n; i++ )
#define lpu(i,j,n)		for(ll i = (j) ; i < (ll) n ; i++ )
#define lpd(i,j,n)		for(ll i = (j) ; i >= (ll) n ; i-- )

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;

ll arr[1005] ;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s ;
	cin >> s ;
	ll ln = s.length() ,lq = -1;
	ll x = 0 ,st = 0  , e;
	lp(i , ln)
	{
		if(s[i] == ',')
		{
			lq = i ;
			e = i-1 ;
			ll k = 1 ,num = 0 ;
			while ( e >= st)
			{
				num += ((ll)(s[e]-'0')) * k ;
				k *= 10 ;
				e--;
			}
		//	cout << num << endl;
			arr[x++] = num ;
			st = i+1 ;
		}
	}
	if(lq != -1)
	{
		ll num = 0 , k = 1 ;
		lpd(j , ln-1 , lq+1)
		{
			num += (ll)(s[j]-'0') * k ;
			k *= 10 ;
		}
		arr[x++] = num ;
	}
	sort( arr , arr + x );
	/*lp(i , x)
	{
		cout << arr[i] <<" " ;
	}
	cout << endl ;*/
	cout << arr[0] ;
	bool h = false ;
	ll ans = -1;
	lpu( i ,1, x )
	{
		if(arr[i] == arr[i-1])
			continue ;
		if(arr[i]-1 == arr[i-1])
		{
			h = true;
		}
		else
		{
			 ans = arr[i] ;
			if(h)
			{
				cout << "-" << arr[i-1] << "," << arr[i] ;
				h = false ;
			}
			else
			{
				//h = false ;
				cout << "," << arr[i] ;
			}
		}
	}
	if(arr[x-1] != ans )
		cout << "-" << arr[x-1] ;
	cout << endl ;
	return 0;
}


/*	THE NAME OF ALLAH	*/
/*
                                       __
   |   |        --          |        /    \
  | | | |      /  |      __ |       |      |
  |  |  |     /---      |   |      |        |
  |     |    |         |    |       |      |
  |     |    |____      |__ |        \ __ /

	   	      _       _
        	/   \   /   \
           /     \ /     \
          |       |       |
           |             |             \
 |\ _ _ _ _ |           |  _ _ _ _ _ _ _\
 |/          |         |                /
              |       |                /
               |     |
      _ _ _     |   |             _ _
    /            | |            /     \
   /              |            |       |
  /                             \     /
 |                               \
 |                                \
 |                                 \
  \                           /     \
   \                         |       |
    \ _ _ _                   \ _ _ /

*/

#include<iostream>
#include<fstream>
#include<algorithm>
#include<set>
#include<string.h>
#include<map>
#include<list>
#include<iomanip>
#include <cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<iterator>
using namespace std;

#define all(v)			((v).begin(),(v).end())
#define sz(v)			((ll)(v).size())
#define clr(v,d)		memset((v),(d),sizeof(v))
#define rep(i,v)		for(ll i = 0 ; i < (ll) sz(v) ; i++ )
#define lp(i,n)			for(ll i = 0 ; i < (ll) n; i++ )
#define lpu(i,j,n)		for(ll i = (j) ; i < (ll) n ; i++ )
#define lpd(i,j,n)		for(ll i = (j) ; i >= (ll) n ; i-- )

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;

ll arr[1005] ;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s ;
	cin >> s ;
	ll ln = s.length() ,lq = -1;
	ll x = 0 ,st = 0  , e;
	lp(i , ln)
	{
		if(s[i] == ',')
		{
			lq = i ;
			e = i-1 ;
			ll k = 1 ,num = 0 ;
			while ( e >= st)
			{
				num += ((ll)(s[e]-'0')) * k ;
				k *= 10 ;
				e--;
			}
		//	cout << num << endl;
			arr[x++] = num ;
			st = i+1 ;
		}
	}
	if(lq == -1)
	{
			ll num1 = 0 ;
			ll k1 = 1 ;
			lpd(j,ln-1,0)
			{
				num1 += (ll)(s[j]-'0') * k1 ;
				k1 *= 10 ;
			}
			cout << num1 << endl;
			return 0 ;
	}
	if(lq != -1)
	{
		ll num = 0 , k = 1 ;
		lpd(j , ln-1 , lq+1)
		{
			num += (ll)(s[j]-'0') * k ;
			k *= 10 ;
		}
		arr[x++] = num ;
	}
	sort( arr , arr + x );

	cout << arr[0] ;
	bool h = false ;
	ll ans = arr[0];
	lpu( i ,1, x )
	{
		if(arr[i] == arr[i-1])
			continue ;
		if(arr[i]-1 == arr[i-1])
		{
			h = true;
		}
		else
		{
			ans = arr[i] ;
			if(h)
			{
				cout << "-" << arr[i-1] << "," << arr[i] ;
				h = false ;
			}
			else
			{
				//h = false ;
				cout << "," << arr[i] ;
			}
		}
	}
	if(arr[x-1] != ans )
		cout << "-" << arr[x-1] ;
	cout << endl ;
	return 0;
}


/*	THE NAME OF ALLAH	*/
/*
                                       __
   |   |        --          |        /    \
  | | | |      /  |      __ |       |      |
  |  |  |     /---      |   |      |        |
  |     |    |         |    |       |      |
  |     |    |____      |__ |        \ __ /

	   	      _       _
        	/   \   /   \
           /     \ /     \
          |       |       |
           |             |             \
 |\ _ _ _ _ |           |  _ _ _ _ _ _ _\
 |/          |         |                /
              |       |                /
               |     |
      _ _ _     |   |             _ _
    /            | |            /     \
   /              |            |       |
  /                             \     /
 |                               \
 |                                \
 |                                 \
  \                           /     \
   \                         |       |
    \ _ _ _                   \ _ _ /

*/

#include<iostream>
#include<fstream>
#include<algorithm>
#include<set>
#include<string.h>
#include<map>
#include<list>
#include<iomanip>
#include <cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<iterator>
using namespace std;

#define all(v)			((v).begin(),(v).end())
#define sz(v)			((ll)(v).size())
#define clr(v,d)		memset((v),(d),sizeof(v))
#define rep(i,v)		for(ll i = 0 ; i < (ll) sz(v) ; i++ )
#define lp(i,n)			for(ll i = 0 ; i < (ll) n; i++ )
#define lpu(i,j,n)		for(ll i = (j) ; i < (ll) n ; i++ )
#define lpd(i,j,n)		for(ll i = (j) ; i >= (ll) n ; i-- )

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;

ll arr[1005] ;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s ;
	cin >> s ;
	ll ln = s.length() ,lq = -1;
	ll x = 0 ,st = 0  , e;
	lp(i , ln)
	{
		if(s[i] == ',')
		{
			lq = i ;
			e = i-1 ;
			ll k = 1 ,num = 0 ;
			while ( e >= st)
			{
				num += ((ll)(s[e]-'0')) * k ;
				k *= 10 ;
				e--;
			}
		//	cout << num << endl;
			arr[x++] = num ;
			st = i+1 ;
		}
	}
	if(lq != -1)
	{
		ll num = 0 , k = 1 ;
		lpd(j , ln-1 , lq+1)
		{
			num += (ll)(s[j]-'0') * k ;
			k *= 10 ;
		}
		arr[x++] = num ;
	}
	sort( arr , arr + x );
	/*lp(i , x)
	{
		cout << arr[i] <<" " ;
	}
	cout << endl ;*/
	cout << arr[0] ;
	bool h = false ;
	lpu( i ,1, x )
	{
		if(arr[i] == arr[i-1])
			continue ;
		if(arr[i]-1 == arr[i-1])
		{
			h = true;
		}
		else
		{
			if(h)
				cout << "-" << arr[i-1] << "," << arr[i] ;
			else
			{
				h = false ;
				cout << "," << arr[i] ;
			}
		}
	}
	if(h)
		cout << "-" << arr[x-1] ;
	cout << endl ;
	return 0;
}


/*	THE NAME OF ALLAH	*/
/*
                                       __
   |   |        --          |        /    \
  | | | |      /  |      __ |       |      |
  |  |  |     /---      |   |      |        |
  |     |    |         |    |       |      |
  |     |    |____      |__ |        \ __ /

	   	      _       _
        	/   \   /   \
           /     \ /     \
          |       |       |
           |             |             \
 |\ _ _ _ _ |           |  _ _ _ _ _ _ _\
 |/          |         |                /
              |       |                /
               |     |
      _ _ _     |   |             _ _
    /            | |            /     \
   /              |            |       |
  /                             \     /
 |                               \
 |                                \
 |                                 \
  \                           /     \
   \                         |       |
    \ _ _ _                   \ _ _ /

*/

#include<iostream>
#include<fstream>
#include<algorithm>
#include<set>
#include<string.h>
#include<map>
#include<list>
#include<iomanip>
#include <cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<iterator>
using namespace std;

#define all(v)			((v).begin(),(v).end())
#define sz(v)			((ll)(v).size())
#define clr(v,d)		memset((v),(d),sizeof(v))
#define rep(i,v)		for(ll i = 0 ; i < (ll) sz(v) ; i++ )
#define lp(i,n)			for(ll i = 0 ; i < (ll) n; i++ )
#define lpu(i,j,n)		for(ll i = (j) ; i < (ll) n ; i++ )
#define lpd(i,j,n)		for(ll i = (j) ; i >= (ll) n ; i-- )

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;

ll arr[1005] ;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s ;
	cin >> s ;
	ll ln = s.length() ,lq = -1;
	ll x = 0 ,st = 0  , e;
	lp(i , ln)
	{
		if(s[i] == ',')
		{
			lq = i ;
			e = i-1 ;
			ll k = 1 ,num = 0 ;
			while ( e >= st)
			{
				num += ((ll)(s[e]-'0')) * k ;
				k *= 10 ;
				e--;
			}
		//	cout << num << endl;
			arr[x++] = num ;
			st = i+1 ;
		}
	}
	if(lq != -1)
	{
		ll num = 0 , k = 1 ;
		lpd(j , ln-1 , lq+1)
		{
			num += (ll)(s[j]-'0') * k ;
			k *= 10 ;
		}
		arr[x++] = num ;
	}
	sort( arr , arr + x );
	/*lp(i , x)
	{
		cout << arr[i] <<" " ;
	}
	cout << endl ;*/
	cout << arr[0] ;
	bool h = false ;
	ll ans = -1;
	lpu( i ,1, x )
	{
		if(arr[i] == arr[i-1])
			continue ;
		if(arr[i]-1 == arr[i-1])
		{
			h = true;
		}
		else
		{
			 ans = arr[i] ;
			if(h)
				cout << "-" << arr[i-1] << "," << arr[i] ;
			else
			{
				h = false ;
				cout << "," << arr[i] ;
			}
		}
	}
	if(arr[x-1] != ans )
		cout << "-" << arr[x-1] ;
	cout << endl ;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int a[105],tot=1;
bool vis[1005];

void init()
{
	for(int i=0;i<s.size();i++)
	{
		if(s[i]==',') tot++;
		else
		{
			a[tot]*=10;
			a[tot]+=s[i]-'0';
		}
	}
	for(int i=1;i<=tot;i++) vis[a[i]]=1;
	return ;
}

int main()
{
	cin>>s;
	init();
//	for(int i=1;i<=tot;i++) cout<<a[i]<<" "; cout<<endl;
	int l=-1,r;
	for(int i=1;i<=1000;i++)
	{
		if(vis[i] && l==-1) l=i;
		if(vis[i]) r=i;
		else if(l!=-1)
		{
			if(l==r) cout<<l<<',';
			else cout<<l<<'-'<<r<<',';
			l=-1;
		}
	}cout<<'\b'<<' '<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, a[N]={0};
bool t[1005];
int main(){
	std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	freopen("test_file/in.txt", "r", stdin);
//	freopen("test_file/out.out", "w", stdout);
	memset(a, 0, sizeof(a));
	int i = 0;
	char c;
	do{
		while (1){
			c = getchar();
			if (!isdigit(c)) break;
			a[i] *= 10;
			a[i] += c-'0';
		}
		if (c != EOF) t[a[i]] = 1;
		i++;
	}while (c != EOF);
	n = i-1;
	int f = 1;
	for (int i = 0; i <= 1000; i++){
		if (!t[i]) continue;
		if ((i == 1 || !t[i-1]) && (i == n || !t[i+1])){
			if (!f) cout << ',';
			cout << i;
		}else if (i == 1 || !t[i-1]){
			if (!f) cout << ',';
			cout << i << '-';
		}else if (i == n || !t[i+1]) cout << i;
		f = 0;
	}
    return 0;
}


#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 1000000
#define LL long long
using namespace std;
char x;
LL n,a[N],ok=1,b[N],j=0,start;
int main()
{
	ios::sync_with_stdio(false);
	while(cin>>x)
	{
		if(x!=',')
		a[int(x-48)]++;
	}
	for(int i=1;i<=1000;i++)
	if(a[i]!=0)
	b[j++]=i;
	start=b[0];
	for(int i=0;i<j;i++)
	{
		if(b[i]+1==b[i+1])
        ok++;
        else
        {
            if(ok==1&&i!=j-1)
            cout<<b[i]<<",";
            if(ok!=1&&i!=j-1)
        	cout<<start<<"-"<<b[i]<<",";
            if(ok==1&&i==j-1)
            cout<<b[i]<<endl;
            if(ok!=1&&i==j-1)
            cout<<start<<"-"<<b[i]<<endl;
            ok=1;
            start=b[i+1];
        }
	}
	return 0;
}


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

string str;
int n,s,x;
bool cnt[1001],e;

int main(){
	cin>>str;
	int i;
	for(i=0;i<str.size();i++){
		if(str[i]==','){
			cnt[s]=1;
			s=0;
		}else{
			x=str[i]-'0';
			s=s*10+x;
		}
	}
	cnt[s]=1;
	for(i=0;i<1001;i++){
		if(cnt[i]){
			if(e){
				cout<<",";
			}
			cout<<i;
			if(cnt[i+1]){
				while(cnt[i+1]){
					i++;
				}
				cout<<"-"<<i;
			}
			e=1;
		}
	}
	return 0;
}


#include<cmath>
#include<cstdio>
using namespace std;
const int N=1e4+5;
int n=1,o,f;
char x;
bool flag[N],first=true;
int main()
{
    scanf("%d",&o);
    flag[o]=true;
    while(scanf("%c",&x)!=EOF)
    {
        scanf("%d",&o);
        flag[o]=true;
        n++;
    }
    int start,sum=1;
    for(int i=0;i<=1005;i++)
    {
        if(!flag[i])continue;
        if(sum==1)start=i;
        if(flag[i+1])sum++;
        if(!flag[i+1])
        {
            if(!first)printf(",");
            if(first)first=false;
            if(sum==1)printf("%d",i);
            if(sum==2)printf("%d,%d",start,i);
            if(sum>=3)printf("%d-%d",start,i);
            sum=1;
        }
    }
    return 0;
}


#include<stdio.h>
using namespace std;
int a[105],b[1005],flag[3];
int read(){
	int s=0;
	char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9'){
		s=s*10+c-'0';
		c=getchar();
	}
	if(c!=',')flag[1]=1;
	return s;
}
int main(){
	int i,ans=0,flag1=1;
	for(i=1;flag[1]==0;i++){
		a[i]=read();
		b[a[i]]++;
	}
	for(i=1;i<=1000;i++){
		if(ans==0&&b[i]){
			ans=1;continue;
		}
		if(b[i]&&b[i-1])ans++;
		if(b[i]==0&&b[i-1]){
			if(flag1){
				flag1=0;
				if(ans>1)printf("%d-%d",i-ans,i-1);
				else printf("%d",i-1);
			}
			else{
				if(ans>1)printf(",%d-%d",i-1-ans,i-1);
				else printf(",%d",i-1);
			}
			ans=0;
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>

int p[1001],maxx=-1;

using namespace std;
int main()
{
	freopen("a.in","r",stdin);
	//freopen(".out","w",stdout);

	int n,m;
	char s;while(cin>>m>>s){
		p[m]=1,maxx=max(maxx,m);
	}p[m]=1,maxx=max(maxx,m);
	for(int i=0;i<=1000;++i)
	{
		if(p[i]==1)
		{
			printf("%d",i);
			int s=i;
			while(p[++i]==1){}i--;
			if(i!=s)printf("-%d",i);
			if(i!=maxx)printf(",");
		}

	}

	fclose(stdin);
	//fclose(stdout);
 	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	set<int> b;
	string s;
	int a[10001]={0},lenn=0;
	getline(cin,s);
	int len=s.length();
	for(int i=0;i<len;i++)
	{
		int x=0;
		while(isdigit(s[i]))
		{
			x=x*10+s[i]-'0';
			i++;
		}
		b.insert(x);
	}
	set<int>::iterator it=b.begin();
	for(it;it!=b.end();it++)
	{
		a[++lenn]=(*it);
	}
	int now=1;
	printf("%d",a[1]);
	for(int i=2;i<=lenn;i++)
	{
		if(a[i]!=1+a[i-1])
		{
			if(now==1)
			{
				printf(",%d",a[i]);
			}
			else
			{
				printf("-%d,%d",a[i-1],a[i]);
				now=1;
			}
		}
		else
		{
			now++;
		}
	}
	printf("\n");
	return 0;
}


#include <iostream>

using namespace std;

bool a[1010];

int main()
{
	char tmp;
	int x;
	int maxx = -1;
	while (true)
	{
		cin >> x;
		tmp = getchar();
		a[x] = true;
		maxx = x > maxx ? x : maxx;
		if (tmp == '\n') break;
	}
	int st = 0;
	bool outfirst = true;
	int j;
	for (int i = 1; i <= 1000; ++i)
	{
		j = i;
		if (a[i] && a[i + 1])
		{
			for (j = i; a[j] && a[j + 1]; ++j)
			{
				;
			}
			if (outfirst) cout << i << "-" << j, outfirst = false;
			else cout << "," << i << "-" << j;
			i += j - i;
		}
		else if ((a[i] && !a[i + 1]) && (i + 1 != maxx))
		{
			if (outfirst) cout << i, outfirst = false;
			else cout << "," << i;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int a[105],tot=1;
bool vis[1005];
int maxa;

void init()
{
	for(int i=0;i<s.size();i++)
	{
		if(s[i]==',') maxa=max(a[tot],maxa),tot++;
		else
		{
			a[tot]*=10;
			a[tot]+=s[i]-'0';
		}
	}
	maxa=max(a[tot],maxa);
	for(int i=1;i<=tot;i++) vis[a[i]]=1;
	return ;
}

int main()
{
	cin>>s;
	init();
//	for(int i=1;i<=tot;i++) cout<<a[i]<<" "; cout<<endl;
	int l=-1,r;
	for(int i=1;i<=1003;i++)
	{
		if(vis[i] && l==-1) l=i;
		if(vis[i]) r=i;
		else if(l!=-1)
		{
			if(l==r) cout<<l;
			else cout<<l<<'-'<<r;
			if(i-1!=maxa) cout<<',';
			l=-1;
		}
	}cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x[105];
int main()
{
	int a=0,flag=0;
	char s;
	for(;;)
	{
		if(a==0) scanf("%d",&x[a++]);
		else
		{
			if(getchar()==EOF) break;
			scanf("%d",&x[a++]);
		}
	}
	sort(x,x+a);
	a=unique(x,x+a)-x;
	for(int i=0;i<a;i++)
	{
		if(x[i]==0) continue;
		int q=1;
		for(int j=i+1;j<a;j++)
			if(x[j]-x[j-1]!=1) break;
			else q++;
		if(q==1)
		{
			if(flag==1) putchar(',');
			else flag=1;
			cout<<x[i];
		}
		else
		{
			if(flag==1) putchar(',');
			else flag=1;
			cout<<x[i]<<'-'<<x[i+q-1];
		}
		i+=(q-1);
	}
}


#include <iostream>
#include <cstdio>
using namespace std;
int maxx, x, sum, flag, i, v[1100];
char c;
int main() {
	c = getchar();
	while(c != '\n') {
		if (c == ',') {
			maxx = max(maxx, sum);
			v[sum] = 1;
			sum = 0;
		}
		else sum = sum * 10 + int(c - '0');
		c = getchar();
	}
	maxx = max(maxx, sum);
	v[sum] = 1;
	sum = 0;
	for (i = 1; i <= maxx; i++) {
		if (v[i] && v[i + 1]) sum++;
		else {
			if (sum == 0 && !v[i]) continue;
			if (flag) cout << ',';
			if (!flag) flag = 1;
			if (sum == 0) cout << i;
			else cout << i - sum << '-' << i;
			sum = 0;
		}
	}
	return 0;
}


#include<cmath>
#include<cstdio>
using namespace std;
const int N=1e4+5;
int n=1,o,f;
char x;
bool flag[N],first=true;;
int main()
{
    scanf("%d",&o);
    flag[o]=true;
    while(scanf("%c",&x)!=EOF)
    {
        scanf("%d",&o);
        flag[o]=true;
        n++;
    }
    int sum=1,start;
    for(int i=1;i<=1000;i++)
    {
        if(!flag[i])continue;
        if(sum==1)start=i;
        if(flag[i]&&flag[i+1])sum++;
        if(flag[i]&&!flag[i+1]&&sum==1)
        {
            if(first)
            {
                printf("%d",i);
                first=false;
            }
            else printf(",%d",i);
            sum=1;
        }
        if(flag[i]&&!flag[i+1]&&sum==2)
        {
            if(first)
            {
                printf("%d,%d",start,i);
                first=false;
            }
            else printf(",%d,%d",start,i);
            sum=1;
        }
        if(flag[i]&&!flag[i+1]&&sum>=3)
        {
            if(first)
            {
                printf("%d-%d",start,i);
                first=false;
            }
            else
            printf(",%d-%d",start,i);
            sum=1;
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
// #include<cstring>
// #include<algorithm>
// #include<string>
// #include<cmath>

int p[1001],maxx=-1;

using namespace std;
int main()
{
// 	freopen("a.in","r",stdin);
	//freopen(".out","w",stdout);

	int n,m;
	char s;while(cin>>m>>s){
		p[m]=1,maxx=max(maxx,m);
	}p[m]=1,maxx=max(maxx,m);
	for(int i=0;i<=1000;++i)
	{
		if(p[i]==1)
		{
			printf("%d",i);
			int s=i;
			while(p[++i]==1){}i--;
			if(i!=s)printf("-%d",i);
			if(i!=maxx)printf(",");
		}

	}

// 	fclose(stdin);
	//fclose(stdout);
 	return 0;
}
//hellobig_tq


#include<iostream>
#include<cstdio>
// #include<cstring>
// #include<algorithm>
// #include<string>
// #include<cmath>

int p[1001],maxx=-1;

using namespace std;
int main()
{
// 	freopen("a.in","r",stdin);
	//freopen(".out","w",stdout);

	int n,m;
	char s;while(cin>>m>>s){
		p[m]=1,maxx=max(maxx,m);
	}p[m]=1,maxx=max(maxx,m);
	for(int i=0;i<=1000;++i)
	{
		if(p[i]==1)
		{
			printf("%d",i);
			int s=i;
			while(p[++i]==1){}i--;
			if(i!=s)printf("-%d",i);
			if(i!=maxx)printf(",");
		}

	}

// 	fclose(stdin);
	//fclose(stdout);
 	return 0;
}
//hellobig_tq//hellobig_tq


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

using namespace std;
/*
 g++ pageNumber.cpp -o pageNumber.exe -std=c++11

 1,2,3,1,1,2,6,6,2
 3,2,1
 30,20,10
 */
int main() {
    set<int> final;
    string pal;
    string aux = "";
    getline (cin, pal);
    //cout << "tamaño" << pal.size() << endl;
    for(int i = 0; i < pal.size();i++){
        if(pal[i] != ','){
            aux=aux+pal[i];

        }else{
            int var = stoi(aux);
            final.insert(var);
            aux = "";
        }
    }
    //cout<<"aux" << aux << endl;
    int var = stoi(aux);
    final.insert(var);

    bool uno = true;
    int cont = 0;
    int ante = 0;
    for(auto it = final.begin(); it != final.end(); it++){
        //cout << *it << endl;
        if(uno){
            uno = false;
            cout<<*it;
            ante = *it;
            cont++;
        }else{
            if((*it-ante == 1)){
                ante = *it;
                cont++;
            }else{
                if(cont >= 2){
                    it--;
                    cout<<"-"<<*it;
                    it++;
                    cont = 0;
                }

                cout<<","<<*it;
            }
        }
    }
    if(cont > 1 ){

        auto iter = final.end();
        int ultimo = *iter;

        if(ante == *iter){
            cout<<"-"<< ultimo;
        }else{
            for(int i = 0; i < cont;i++){
                iter--;
            }
            cout<<","<<*iter << "-"<<ultimo;
        }

    }

    cout <<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef int integer;
vector<string> split(string s, string border);

#define int long long
#define double long double
#define make(type, n) type n; cin >> n
#define ALL(x) (x).begin(), (x).end()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(i, count) for(int i = 0; i <(count); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define make_v(a, n) VI a(n); FOR(i, n) cin >> a[i];
#define get_bit(mask, pos) ((mask >> pos) & 1)
#define set_bit_0(mask, pos) (mask & (~(1 << pos)))
#define set_bit_1(mask, pos) (mask | (1 << pos))
#define sqrt(x) sqrtl(x)
#define dis(x1, y1, x2, y2) hypotl((x2-x1), (y2-y1))
#define sqr(x) ((x)*(x))

void set_1(set<PII> &s, set<PII>::iterator &it, int val_1){
    int val_2 = it->second;
    it = s.erase(it);
    s.insert({val_1, val_2});
}

void set_2(set<PII> &s, set<PII>::iterator &it, int val_2){
    int val_1 = it->first;
    it = s.erase(it);
    s.insert({val_1, val_2});
}

void solve(){
    make(int, n);
    make(int, q);

    set<PII> holidays;
    int ans = 0;

    FOR(i, q){
        make(int, l);
        make(int, r);
        make(int, k);

        auto it = holidays.upper_bound({l, 0});
        if (it != holidays.begin()) --it;

        //УДАЛЕНИЕ ЭЛЕМЕНТОВ
        //if (!(k == 1 && it->first < l && it->second > r)) {
            while (it != holidays.end()) {
                if (it->second < l) {
                    ++it;
                    continue;
                }

                if (it->first > r) {
                    break;
                }

                if (it->first < l && it->second >= l && it->second <= r) {
                    ans -= it->second - l + 1;

                    set_2(holidays, it, l - 1);
                    continue;
                }

                if (it->first >= l && it->first <= r && it->second > r) {
                    ans -= r - it->first + 1;

                    set_1(holidays, it, r + 1);
                    continue;
                }

                if (it->first >= l && it->second <= r) {
                    ans -= it->second - it->first + 1;

                    it = holidays.erase(it);
                    continue;
                }

                if (it->first < l && it->second > r) {
                    ans -= r - l + 1;
                    holidays.insert({it->first, l - 1});
                    holidays.insert({r + 1, it->second});

                    it = holidays.erase(it);
                    continue;
                }
            }

            if (k == 1) {
                auto it = holidays.upper_bound({l, 0});
                if (it != holidays.begin()) --it;

                while (it != holidays.end() && it->first <= r) {
                    if (it->first < l && (it->second == l)) {
                        l = it->first;

                        it = holidays.erase(it);
                        continue;
                    }

                    if ((it->first == r) && it->second > r) {
                        r = it->second;

                        it = holidays.erase(it);
                        continue;
                    }

                    ++it;
                }

                holidays.insert({l, r});
                ans += r - l + 1;
            }
        //}

        cout << n-ans << endl;
    }
}

integer main(integer argc, char* argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie();

    if (argc > 1 && (string) argv[1] == "file") {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

        int number_sample = 1;
        do {
            cout << "Sample #" << number_sample << ":" << endl;
            cerr << "Sample #" << number_sample << ":" << endl;

            solve();
            number_sample++;

            cout << endl;
            cerr << endl;
        } while (!cin.eof());
    } else {
        cerr.clear(ios_base::badbit);
        solve();
    }
}

vector<string> split(string s, string border){
    vector<string> ans;
    int pos_end;

    while((pos_end = s.find(border)) != string::npos){
        if (pos_end) ans.push_back(s.substr(0, pos_end));
        s = s.substr(pos_end + border.size());
    }

    return ans;
}


#include <bits/stdc++.h>

using namespace std;

typedef int integer;
vector<string> split(string s, string border);

#define int long long
#define double long double
#define make(type, n) type n; cin >> n
#define ALL(x) (x).begin(), (x).end()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(i, count) for(int i = 0; i <(count); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define make_v(a, n) VI a(n); FOR(i, n) cin >> a[i];
#define get_bit(mask, pos) ((mask >> pos) & 1)
#define set_bit_0(mask, pos) (mask & (~(1 << pos)))
#define set_bit_1(mask, pos) (mask | (1 << pos))
#define sqrt(x) sqrtl(x)
#define dis(x1, y1, x2, y2) hypotl((x2-x1), (y2-y1))
#define sqr(x) ((x)*(x))

void set_1(set<PII> &s, set<PII>::iterator &it, int val_1){
    int val_2 = it->second;
    s.erase(it);
    s.insert({val_1, val_2});
}

void set_2(set<PII> &s, set<PII>::iterator &it, int val_2){
    int val_1 = it->first;
    s.erase(it);
    s.insert({val_1, val_2});
}

void solve(){
    make(int, n);
    make(int, q);

    set<PII> holidays;
    int ans = 0;

    FOR(i, q){
        make(int, l);
        make(int, r);
        make(int, k);

        auto it = holidays.upper_bound({l, 0});
        if (it != holidays.begin()) --it;

        //УДАЛЕНИЕ ЭЛЕМЕНТОВ
        while (it != holidays.end()){
            if (it->second  < l){
                ++it;
                continue;
            }

            if (it->first > r){
                break;
            }

            if (it->first < l && it->second >= l && it->second <= r){
                ans -= it->second - l + 1;
                set_2(holidays, it, l-1);

                ++it;
                continue;
            }

            if (it->first >= l && it->first <= r && it->second > r){
                ans -= r - it->first + 1;
                set_1(holidays, it, r+1);

                ++it;
                continue;
            }

            if (it->first >= l && it->second <= r){
                ans -= it->second - it->first + 1;

                it = holidays.erase(it);
                continue;
            }

            if (it->first < l && it->second > r){
                ans -= r-l+1;
                holidays.insert({it->first, l-1});
                holidays.insert({r+1, it->second});

                it = holidays.erase(it);
                continue;
            }
        }

        if (k == 1){
            auto it = holidays.upper_bound({l, 0});
            if (it != holidays.begin()) --it;

            while (it != holidays.end() && it->first <= r){
                if (it->first < l && it->second == l){
                    l = it->first;

                    it = holidays.erase(it);
                    continue;
                }

                if (it->first == r && it->second > r){
                    r = it->second;

                    it = holidays.erase(it);
                    continue;
                }

                ++it;
            }

            holidays.insert({l, r});
            ans += r-l+1;
        }

        cout << n-ans << endl;
    }
}

integer main(integer argc, char* argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie();

    if (argc > 1 && (string) argv[1] == "file") {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

        int number_sample = 1;
        do {
            cout << "Sample #" << number_sample << ":" << endl;
            cerr << "Sample #" << number_sample << ":" << endl;

            solve();
            number_sample++;

            cout << endl;
            cerr << endl;
        } while (!cin.eof());
    } else {
        cerr.clear(ios_base::badbit);
        solve();
    }
}

vector<string> split(string s, string border){
    vector<string> ans;
    int pos_end;

    while((pos_end = s.find(border)) != string::npos){
        if (pos_end) ans.push_back(s.substr(0, pos_end));
        s = s.substr(pos_end + border.size());
    }

    return ans;
}


#include <bits/stdc++.h>

using namespace std;

typedef int integer;
vector<string> split(string s, string border);

#define int long long
#define double long double
#define make(type, n) type n; cin >> n
#define ALL(x) (x).begin(), (x).end()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(i, count) for(int i = 0; i <(count); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define make_v(a, n) VI a(n); FOR(i, n) cin >> a[i];
#define get_bit(mask, pos) ((mask >> pos) & 1)
#define set_bit_0(mask, pos) (mask & (~(1 << pos)))
#define set_bit_1(mask, pos) (mask | (1 << pos))
#define sqrt(x) sqrtl(x)
#define dis(x1, y1, x2, y2) hypotl((x2-x1), (y2-y1))
#define sqr(x) ((x)*(x))

void set_1(set<PII> &s, set<PII>::iterator &it, int val_1){
    int val_2 = it->second;
    s.erase(it);
    s.insert({val_1, val_2});
}

void set_2(set<PII> &s, set<PII>::iterator &it, int val_2){
    int val_1 = it->first;
    s.erase(it);
    s.insert({val_1, val_2});
}

void solve(){
    make(int, n);
    make(int, q);

    set<PII> holidays;
    int ans = 0;

    FOR(i, q){
        make(int, l);
        make(int, r);
        make(int, k);

        auto it = holidays.upper_bound({l, 0});
        if (it != holidays.begin()) --it;

        //УДАЛЕНИЕ ЭЛЕМЕНТОВ
        while (it != holidays.end()){
            if (it->second  < l){
                ++it;
                continue;
            }

            if (it->first > r){
                break;
            }

            if (it->first < l && it->second >= l && it->second < r){
                ans -= it->second - l + 1;
                set_2(holidays, it, l-1);

                ++it;
                continue;
            }

            if (it->first >= l && it->first <= r && it->second > r){
                ans -= r - it->first + 1;
                set_1(holidays, it, r+1);

                ++it;
                continue;
            }

            if (it->first >= l && it->second <= r){
                ans -= it->second - it->first + 1;

                it = holidays.erase(it);
                continue;
            }

            if (it->first < l && it->second > r){
                ans -= r-l+1;
                holidays.insert({it->first, l-1});
                holidays.insert({r+1, it->second});

                it = holidays.erase(it);
                continue;
            }
        }

        if (k == 1){
            holidays.insert({l, r});
            ans += r-l+1;
        }

        cout << n-ans << endl;
    }
}

integer main(integer argc, char* argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie();

    if (argc > 1 && (string) argv[1] == "file") {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

        int number_sample = 1;
        do {
            cout << "Sample #" << number_sample << ":" << endl;
            cerr << "Sample #" << number_sample << ":" << endl;

            solve();
            number_sample++;

            cout << endl;
            cerr << endl;
        } while (!cin.eof());
    } else {
        cerr.clear(ios_base::badbit);
        solve();
    }
}

vector<string> split(string s, string border){
    vector<string> ans;
    int pos_end;

    while((pos_end = s.find(border)) != string::npos){
        if (pos_end) ans.push_back(s.substr(0, pos_end));
        s = s.substr(pos_end + border.size());
    }

    return ans;
}


#include <bits/stdc++.h>

using namespace std;

typedef int integer;
vector<string> split(string s, string border);

#define int long long
#define double long double
#define make(type, n) type n; cin >> n
#define ALL(x) (x).begin(), (x).end()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(i, count) for(int i = 0; i <(count); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define make_v(a, n) VI a(n); FOR(i, n) cin >> a[i];
#define get_bit(mask, pos) ((mask >> pos) & 1)
#define set_bit_0(mask, pos) (mask & (~(1 << pos)))
#define set_bit_1(mask, pos) (mask | (1 << pos))
#define sqrt(x) sqrtl(x)
#define dis(x1, y1, x2, y2) hypotl((x2-x1), (y2-y1))
#define sqr(x) ((x)*(x))

inline void set_1(set<PII> &s, set<PII>::iterator &it, int val_1){
    int val_2 = it->second;
    it = s.erase(it);
    s.insert({val_1, val_2});
}

inline void set_2(set<PII> &s, set<PII>::iterator &it, int val_2){
    int val_1 = it->first;
    it = s.erase(it);
    s.insert({val_1, val_2});
}

void solve(){
    make(int, n);
    make(int, q);

    set<PII> holidays;
    int ans = 0;

    FOR(i, q){
        make(int, l);
        make(int, r);
        make(int, k);

        auto it = holidays.upper_bound({l, 0});
        if (it != holidays.begin()) --it;

        //УДАЛЕНИЕ ЭЛЕМЕНТОВ
        if (!(k == 1 && it->first < l && it->second > r)) {
            while (it != holidays.end()) {
                if (it->second < l) {
                    ++it;
                    continue;
                }

                if (it->first > r) {
                    break;
                }

                if (it->first < l && it->second >= l && it->second <= r) {
                    ans -= it->second - l + 1;

                    set_2(holidays, it, l - 1);
                    continue;
                }

                if (it->first >= l && it->first <= r && it->second > r) {
                    ans -= r - it->first + 1;

                    set_1(holidays, it, r + 1);
                    continue;
                }

                if (it->first >= l && it->second <= r) {
                    ans -= it->second - it->first + 1;

                    it = holidays.erase(it);
                    continue;
                }

                if (it->first < l && it->second > r) {
                    ans -= r - l + 1;
                    holidays.insert({it->first, l - 1});
                    holidays.insert({r + 1, it->second});

                    it = holidays.erase(it);
                    continue;
                }
            }

            if (k == 1) {
                auto it = holidays.upper_bound({l, 0});
                if (it != holidays.begin()) --it;

                while (it != holidays.end()) {
                    if (it->first < l && (it->second == l-1)) {
                        ans -= it->second - it->first + 1;
                        l = it->first;

                        it = holidays.erase(it);
                        continue;
                    }

                    if ((it->first == r+1) && it->second > r) {
                        ans -= it->second - it->first + 1;
                        r = it->second;

                        it = holidays.erase(it);
                        continue;
                    }

                    if (it->first > r){
                        break;
                    }

                    ++it;
                }

                holidays.insert({l, r});
                ans += r - l + 1;
            }
        }

        cout << n-ans << endl;
    }
}

integer main(integer argc, char* argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie();

    if (argc > 1 && (string) argv[1] == "file") {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

        int number_sample = 1;
        do {
            cout << "Sample #" << number_sample << ":" << endl;
            cerr << "Sample #" << number_sample << ":" << endl;

            solve();
            number_sample++;

            cout << endl;
            cerr << endl;
        } while (!cin.eof());
    } else {
        cerr.clear(ios_base::badbit);
        solve();
    }
}

vector<string> split(string s, string border){
    vector<string> ans;
    int pos_end;

    while((pos_end = s.find(border)) != string::npos){
        if (pos_end) ans.push_back(s.substr(0, pos_end));
        s = s.substr(pos_end + border.size());
    }

    return ans;
}


#include <bits/stdc++.h>

using namespace std;

typedef int integer;
vector<string> split(string s, string border);

#define int long long
#define double long double
#define make(type, n) type n; cin >> n
#define ALL(x) (x).begin(), (x).end()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(i, count) for(int i = 0; i <(count); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define make_v(a, n) VI a(n); FOR(i, n) cin >> a[i];
#define get_bit(mask, pos) ((mask >> pos) & 1)
#define set_bit_0(mask, pos) (mask & (~(1 << pos)))
#define set_bit_1(mask, pos) (mask | (1 << pos))
#define sqrt(x) sqrtl(x)
#define dis(x1, y1, x2, y2) hypotl((x2-x1), (y2-y1))
#define sqr(x) ((x)*(x))

void set_1(set<PII> &s, set<PII>::iterator &it, int val_1){
    int val_2 = it->second;
    it = s.erase(it);
    s.insert({val_1, val_2});
}

void set_2(set<PII> &s, set<PII>::iterator &it, int val_2){
    int val_1 = it->first;
    it = s.erase(it);
    s.insert({val_1, val_2});
}

void solve(){
    make(int, n);
    make(int, q);

    set<PII> holidays;
    int ans = 0;

    FOR(i, q){
        make(int, l);
        make(int, r);
        make(int, k);

        auto it = holidays.upper_bound({l, 0});
        if (it != holidays.begin()) --it;

        //УДАЛЕНИЕ ЭЛЕМЕНТОВ
        while (it != holidays.end()){
            if (it->second  < l){
                ++it;
                continue;
            }

            if (it->first > r){
                break;
            }

            if (it->first < l && it->second >= l && it->second <= r){
                ans -= it->second - l + 1;

                set_2(holidays, it, l-1);
                continue;
            }

            if (it->first >= l && it->first <= r && it->second > r){
                ans -= r - it->first + 1;

                set_1(holidays, it, r+1);
                continue;
            }

            if (it->first >= l && it->second <= r){
                ans -= it->second - it->first + 1;

                it = holidays.erase(it);
                continue;
            }

            if (it->first < l && it->second > r){
                ans -= r-l+1;
                holidays.insert({it->first, l-1});
                holidays.insert({r+1, it->second});

                it = holidays.erase(it);
                continue;
            }
        }

        if (k == 1){
            auto it = holidays.upper_bound({l, 0});
            if (it != holidays.begin()) --it;

            while (it != holidays.end() && it->first <= r){
                if (it->first < l && it->second == l){
                    l = it->first;

                    it = holidays.erase(it);
                    continue;
                }

                if (it->first == r && it->second > r){
                    r = it->second;

                    it = holidays.erase(it);
                    continue;
                }

                ++it;
            }

            holidays.insert({l, r});
            ans += r-l+1;
        }

        cout << n-ans << endl;
    }
}

integer main(integer argc, char* argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie();

    if (argc > 1 && (string) argv[1] == "file") {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

        int number_sample = 1;
        do {
            cout << "Sample #" << number_sample << ":" << endl;
            cerr << "Sample #" << number_sample << ":" << endl;

            solve();
            number_sample++;

            cout << endl;
            cerr << endl;
        } while (!cin.eof());
    } else {
        cerr.clear(ios_base::badbit);
        solve();
    }
}

vector<string> split(string s, string border){
    vector<string> ans;
    int pos_end;

    while((pos_end = s.find(border)) != string::npos){
        if (pos_end) ans.push_back(s.substr(0, pos_end));
        s = s.substr(pos_end + border.size());
    }

    return ans;
}


#include <bits/stdc++.h>

using namespace std;

typedef int integer;
vector<string> split(string s, string border);

//#define int long long
#define double long double
#define make(type, n) type n; cin >> n
#define ALL(x) (x).begin(), (x).end()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(i, count) for(int i = 0; i <(count); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define PII pair<int, int>
#define make_v(a, n) VI a(n); FOR(i, n) cin >> a[i];
#define get_bit(mask, pos) ((mask >> pos) & 1)
#define set_bit_0(mask, pos) (mask & (~(1 << pos)))
#define set_bit_1(mask, pos) (mask | (1 << pos))
#define sqrt(x) sqrtl(x)
#define dis(x1, y1, x2, y2) hypotl((x2-x1), (y2-y1))
#define sqr(x) ((x)*(x))

void solve(){
    make(int, n);
    make(int, q);

    set<PII> holidays;
    int ans = 0;

    FOR(i, q){
        make(int, l);
        make(int, r);
        make(int, k);

        auto it = holidays.upper_bound({l, r});
        if (it != holidays.begin()) --it;

        //УДАЛЕНИЕ ЭЛЕМЕНТОВ
        if (!(k == 1 && it->first < l && it->second > r)) {
            while (it != holidays.end()) {
                if (it->second < l) {
                    ++it;
                    continue;
                }

                if (it->first > r) {
                    break;
                }

                if (it->first < l && it->second >= l && it->second <= r) {
                    ans -= it->second - l + 1;

                    int val_1 = it->first;
                    holidays.insert({val_1, l - 1});
                    it = holidays.erase(it);
                    continue;
                }

                if (it->first >= l && it->first <= r && it->second > r) {
                    ans -= r - it->first + 1;

                    int val_2 = it->second;
                    holidays.insert({r + 1, val_2});
                    it = holidays.erase(it);
                    continue;
                }

                if (it->first >= l && it->second <= r) {
                    ans -= it->second - it->first + 1;

                    it = holidays.erase(it);
                    continue;
                }

                if (it->first < l && it->second > r) {
                    ans -= r - l + 1;
                    holidays.insert({it->first, l - 1});
                    holidays.insert({r + 1, it->second});

                    it = holidays.erase(it);
                    continue;
                }
            }

            if (k == 1) {
                auto it = holidays.upper_bound({l, r});
                if (it != holidays.begin()) --it;

                while (it != holidays.end()) {
                    if (it->first < l && (it->second == l-1)) {
                        ans -= it->second - it->first + 1;
                        l = it->first;

                        it = holidays.erase(it);
                        continue;
                    }

                    if ((it->first == r+1) && it->second > r) {
                        ans -= it->second - it->first + 1;
                        r = it->second;

                        it = holidays.erase(it);
                        continue;
                    }

                    if (it->first > r){
                        break;
                    }

                    ++it;
                }

                holidays.insert({l, r});
                ans += r - l + 1;
            }
        }

        cout << n-ans << endl;
    }
}

integer main(integer argc, char* argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie();

    if (argc > 1 && (string) argv[1] == "file") {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);

        int number_sample = 1;
        do {
            cout << "Sample #" << number_sample << ":" << endl;
            cerr << "Sample #" << number_sample << ":" << endl;

            solve();
            number_sample++;

            cout << endl;
            cerr << endl;
        } while (!cin.eof());
    } else {
        cerr.clear(ios_base::badbit);
        solve();
    }
}

vector<string> split(string s, string border){
    vector<string> ans;
    int pos_end;

    while((pos_end = s.find(border)) != string::npos){
        if (pos_end) ans.push_back(s.substr(0, pos_end));
        s = s.substr(pos_end + border.size());
    }

    return ans;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 1.5e5 + 10, mod = 1e9 + 7;

int n, a[10], b[10], q;
ll l[maxn], r[maxn], x[maxn], y[maxn];

ll v[maxn*100];
int ls[maxn*100], rs[maxn*100], tag[maxn*100], cnt;

void push_down(int p, int l, int r)
{
    if(tag[p] != -1)
    {
        int mid = l + r >> 1;
        if(!ls[p]) ls[p] = ++cnt;
        if(!rs[p]) rs[p] = ++cnt;
        tag[ls[p]] = tag[p];
        tag[rs[p]] = tag[p];
        v[ls[p]] = tag[p] * (mid - l + 1);
        v[rs[p]] = tag[p] * (r - mid);
        tag[p] = -1;
    }
}
void update(int &p, int l, int r, int nl, int nr, ll vv)
{
    if(p == 0) p = ++cnt;
    if(nl <= l and r <= nr)
    {
        v[p] = vv * (r - l + 1);
        tag[p] = vv;
        return;
    }
    int mid = l + r >> 1;
    push_down(p, l, r);
    if(nl <= mid)
        update(ls[p], l, mid, nl, nr, vv);
    if(nr > mid)
        update(rs[p], mid+1, r, nl, nr, vv);
    v[p] = v[ls[p]] + v[rs[p]];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    int root = 0;
    memset(tag, -1, sizeof(tag));
    while(q--)
    {
        int l, r, k; cin >> l >> r >> k;
        if(k == 1) update (root, 1, n, l, r, 1);
        else update (root, 1, n, l, r, 0);
        cout << n - v[1] << '\n';
    }

    return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 1e5 + 10, mod = 1e9 + 7;

int n, a[10], b[10], q;
ll l[maxn], r[maxn], x[maxn], y[maxn];

ll v[maxn*100];
int ls[maxn*100], rs[maxn*100], tag[maxn*100], cnt;

void push_down(int p, int l, int r)
{
    if(tag[p] != -1)
    {
        int mid = l + r >> 1;
        if(!ls[p]) ls[p] = ++cnt;
        if(!rs[p]) rs[p] = ++cnt;
        tag[ls[p]] += tag[p];
        tag[rs[p]] += tag[p];
        v[ls[p]] = tag[p] * (mid - l + 1);
        v[rs[p]] = tag[p] * (r - mid);
        tag[p] = -1;
    }
}
void update(int &p, int l, int r, int nl, int nr, ll vv)
{
    if(p == 0) p = ++cnt;
    if(nl <= l and r <= nr)
    {
        v[p] = vv * (r - l + 1);
        tag[p] = vv;
        return;
    }
    int mid = l + r >> 1;
    push_down(p, l, r);
    if(nl <= mid)
        update(ls[p], l, mid, nl, nr, vv);
    if(nr > mid)
        update(rs[p], mid+1, r, nl, nr, vv);
    v[p] = v[ls[p]] + v[rs[p]];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    int root = 0;
    memset(tag, -1, sizeof(tag));
    while(q--)
    {
        int l, r, k; cin >> l >> r >> k;
        if(k == 1) update (root, 1, n, l, r, 1);
        else update (root, 1, n, l, r, 0);
        cout << n - v[1] << '\n';
    }

    return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 2e5 + 10, mod = 1e9 + 7;

int n, a[10], b[10], q;
ll l[maxn], r[maxn], x[maxn], y[maxn];

ll v[maxn*100];
int ls[maxn*100], rs[maxn*100], tag[maxn*100], cnt;

void push_down(int p, int l, int r)
{
    if(tag[p] != -1)
    {
        int mid = l + r >> 1;
        if(!ls[p]) ls[p] = ++cnt;
        if(!rs[p]) rs[p] = ++cnt;
        tag[ls[p]] = tag[p];
        tag[rs[p]] = tag[p];
        v[ls[p]] = tag[p] * (mid - l + 1);
        v[rs[p]] = tag[p] * (r - mid);
        tag[p] = -1;
    }
}
void update(int &p, int l, int r, int nl, int nr, ll vv)
{
    if(p == 0) p = ++cnt;
    if(nl <= l and r <= nr)
    {
        v[p] = vv * (r - l + 1);
        tag[p] = vv;
        return;
    }
    int mid = l + r >> 1;
    push_down(p, l, r);
    if(nl <= mid)
        update(ls[p], l, mid, nl, nr, vv);
    if(nr > mid)
        update(rs[p], mid+1, r, nl, nr, vv);
    v[p] = v[ls[p]] + v[rs[p]];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    int root = 0;
    memset(tag, -1, sizeof(tag));
    while(q--)
    {
        int l, r, k; cin >> l >> r >> k;
        if(k == 1) update (root, 1, n, l, r, 1);
        else update (root, 1, n, l, r, 0);
        cout << n - v[1] << '\n';
    }

    return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 8e5 + 10, mod = 1e9 + 7;

int n, a[10], b[10], q;
ll l[maxn], r[maxn], x[maxn], y[maxn];

ll v[maxn*100];
int ls[maxn*100], rs[maxn*100], tag[maxn*100], cnt;

void push_down(int p, int l, int r)
{
    if(tag[p] != -1)
    {
        int mid = l + r >> 1;
        if(!ls[p]) ls[p] = ++cnt;
        if(!rs[p]) rs[p] = ++cnt;
        tag[ls[p]] += tag[p];
        tag[rs[p]] += tag[p];
        v[ls[p]] = tag[p] * (mid - l + 1);
        v[rs[p]] = tag[p] * (r - mid);
        tag[p] = -1;
    }
}
void update(int &p, int l, int r, int nl, int nr, ll vv)
{
    if(p == 0) p = ++cnt;
    if(nl <= l and r <= nr)
    {
        v[p] = vv * (r - l + 1);
        tag[p] = vv;
        return;
    }
    int mid = l + r >> 1;
    push_down(p, l, r);
    if(nl <= mid)
        update(ls[p], l, mid, nl, nr, vv);
    if(nr > mid)
        update(rs[p], mid+1, r, nl, nr, vv);
    v[p] = v[ls[p]] + v[rs[p]];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    int root = 0;
    memset(tag, -1, sizeof(tag));
    while(q--)
    {
        int l, r, k; cin >> l >> r >> k;
        if(k == 1) update (root, 1, n, l, r, 1);
        else update (root, 1, n, l, r, 0);
        cout << n - v[1] << '\n';
    }

    return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 1.5e5 + 10, mod = 1e9 + 7;

int n, q;

int v[maxn*100];
int ls[maxn*100], rs[maxn*100], tag[maxn*100], cnt;

void push_down(int p, int l, int r)
{
    if(tag[p] != -1)
    {
        int mid = l + r >> 1;
        if(!ls[p]) ls[p] = ++cnt;
        if(!rs[p]) rs[p] = ++cnt;
        tag[ls[p]] = tag[p];
        tag[rs[p]] = tag[p];
        v[ls[p]] = tag[p] * (mid - l + 1);
        v[rs[p]] = tag[p] * (r - mid);
        tag[p] = -1;
    }
}
void update(int &p, int l, int r, int nl, int nr, ll vv)
{
    if(p == 0) p = ++cnt;
    if(nl <= l and r <= nr)
    {
        v[p] = vv * (r - l + 1);
        tag[p] = vv;
        return;
    }
    int mid = l + r >> 1;
    push_down(p, l, r);
    if(nl <= mid)
        update(ls[p], l, mid, nl, nr, vv);
    if(nr > mid)
        update(rs[p], mid+1, r, nl, nr, vv);
    v[p] = v[ls[p]] + v[rs[p]];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    int root = 0;
    memset(tag, -1, sizeof(tag));
    while(q--)
    {
        int l, r, k; cin >> l >> r >> k;
        if(k == 1) update (root, 1, n, l, r, 1);
        else update (root, 1, n, l, r, 0);
        cout << n - v[1] << '\n';
    }

    return 0;
}


#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 1e5 + 10, mod = 1e9 + 7;

int n, a[10], b[10], q;
ll l[maxn], r[maxn], x[maxn], y[maxn];

ll v[maxn*100];
int ls[maxn*100], rs[maxn*100], tag[maxn*100], cnt;

void push_down(int p, int l, int r)
{
    if(tag[p] != -1)
    {
        int mid = l + r >> 1;
        if(!ls[p]) ls[p] = ++cnt;
        if(!rs[p]) rs[p] = ++cnt;
        tag[ls[p]] = tag[p];
        tag[rs[p]] = tag[p];
        v[ls[p]] = tag[p] * (mid - l + 1);
        v[rs[p]] = tag[p] * (r - mid);
        tag[p] = -1;
    }
}
void update(int &p, int l, int r, int nl, int nr, ll vv)
{
    if(p == 0) p = ++cnt;
    if(nl <= l and r <= nr)
    {
        v[p] = vv * (r - l + 1);
        tag[p] = vv;
        return;
    }
    int mid = l + r >> 1;
    push_down(p, l, r);
    if(nl <= mid)
        update(ls[p], l, mid, nl, nr, vv);
    if(nr > mid)
        update(rs[p], mid+1, r, nl, nr, vv);
    v[p] = v[ls[p]] + v[rs[p]];
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    int root = 0;
    memset(tag, -1, sizeof(tag));
    while(q--)
    {
        int l, r, k; cin >> l >> r >> k;
        if(k == 1) update (root, 1, n, l, r, 1);
        else update (root, 1, n, l, r, 0);
        cout << n - v[1] << '\n';
    }

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e6+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int l,r,son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){l=s,r=t,sum=t-s+1,tag=son[0]=son[1]=0;}
        int mid(){return (r+l)>>1;}
        int len(){return r-l+1;}
        void update(int x){sum=len()*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt;
    dsegtree(int n,int size=maxn){node.resize(maxn);cnt=root=1;node[1]=dsegnode(1,n);}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now){
		if(nd.tag){
			ndl.update(nd.tag);
			ndr.update(nd.tag);
			nd.tag=0;
		}
    }
    void update(int s,int t,int x,int now=1){
    	if(s>nd.r||t<nd.l)return ;
    	if(s<=nd.l&&t>=nd.r) {
			nd.update(x);
			return ;
    	}
    	if(!nd.son[0]){
			node[++cnt]=dsegnode(nd.l,nd.mid());
			nd.son[0]=cnt;
    	}
    	if(!nd.son[1]){
			node[++cnt]=dsegnode(nd.mid()+1,nd.r);
			nd.son[1]=cnt;
    	}
    	pushdown(now);
		update(s,t,x,nd.son[0]);
		update(s,t,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=2e7+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int l,r,son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){l=s,r=t,sum=t-s+1,tag=son[0]=son[1]=0;}
        int mid(){return (r+l)>>1;}
        int len(){return r-l+1;}
        void update(int x){sum=len()*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt;
    dsegtree(int n,int size=maxn){node.resize(maxn);cnt=root=1;node[1]=dsegnode(1,n);}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now){
		if(nd.tag){
			ndl.update(nd.tag);
			ndr.update(nd.tag);
			nd.tag=0;
		}
    }
    void update(int s,int t,int x,int now=1){
    	if(s>nd.r||t<nd.l)return ;
    	if(s<=nd.l&&t>=nd.r) {
			nd.update(x);
			return ;
    	}
    	if(!nd.son[0]){
			node[++cnt]=dsegnode(nd.l,nd.mid());
			nd.son[0]=cnt;
    	}
    	if(!nd.son[1]){
			node[++cnt]=dsegnode(nd.mid()+1,nd.r);
			nd.son[1]=cnt;
    	}
    	pushdown(now);
		update(s,t,x,nd.son[0]);
		update(s,t,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e7+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){sum=t-s+1,tag=son[0]=son[1]=0;}
        void update(int x,int len){sum=len*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt,n,s,t;
    dsegtree(int nn,int size=maxn){
    	n=nn;
    	node.resize(maxn);
    	node[1]=dsegnode(1,n);
    	cnt=root=1;
	}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now,int s,int t){
		if(nd.tag){
			ndl.update(nd.tag,(t+s)/2-s+1);
			ndr.update(nd.tag,t-(t+s)/2+1);
			nd.tag=0;
		}
    }
    void update(int ss,int tt,int x){s=ss,t=tt,update(1,n,x,root);}
    void update(int l,int r,int x,int now){
    	if(s>r||t<l)return ;
    	if(s<=l&&t>=r) {
			nd.update(x,r-l+1);
			return ;
    	}
    	if(!nd.son[0]){
			node[++cnt]=dsegnode(l,(l+r)>>1);
			nd.son[0]=cnt;
    	}
    	if(!nd.son[1]){
			node[++cnt]=dsegnode(((l+r)>>1)+1,r);
			nd.son[1]=cnt;
    	}
    	pushdown(now,l,r);
		update(l,(l+r)>>1,x,nd.son[0]);
		update(((l+r)>>1)+1,r,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e7+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){sum=t-s+1,tag=son[0]=son[1]=0;}
        void update(int x,int len){sum=len*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt,n,s,t;
    dsegtree(int nn,int size=maxn){
    	n=nn;
    	node.resize(maxn);
    	node[1]=dsegnode(1,n);
    	cnt=root=1;
	}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now,int s,int t){
		if(nd.tag){
			ndl.update(nd.tag,(t+s)/2-s+1);
			ndr.update(nd.tag,t-((t+s)/2+1)+1);
			nd.tag=0;
		}
    }
    void update(int ss,int tt,int x){s=ss,t=tt,update(1,n,x,root);}
    void update(int l,int r,int x,int now){
    	if(s>r||t<l)return ;
    	if(s<=l&&t>=r) {
			nd.update(x,r-l+1);
			return ;
    	}
    	if(!nd.son[0]){
			node[++cnt]=dsegnode(l,(l+r)>>1);
			nd.son[0]=cnt;
    	}
    	if(!nd.son[1]){
			node[++cnt]=dsegnode(((l+r)>>1)+1,r);
			nd.son[1]=cnt;
    	}
    	pushdown(now,l,r);
		update(l,(l+r)>>1,x,nd.son[0]);
		update(((l+r)>>1)+1,r,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e7+5e6+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){sum=t-s+1,tag=son[0]=son[1]=0;}
        void update(int x,int len){sum=len*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt,n,s,t;
    dsegtree(int nn){
    	n=nn;
    	node.resize(2);
    	node[1]=dsegnode(1,n);
    	cnt=root=1;
	}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now,int s,int t){
		if(nd.tag){
			ndl.update(nd.tag,(t+s)/2-s+1);
			ndr.update(nd.tag,t-((t+s)/2+1)+1);
			nd.tag=0;
		}
    }
    void update(int ss,int tt,int x){s=ss,t=tt,update(1,n,x,root);}
    void update(int l,int r,int x,int now){
    	if(s>r||t<l)return ;
    	if(s<=l&&t>=r) {
			nd.update(x,r-l+1);
			return ;
    	}
    	if(!nd.son[0]){
			node.push_back(dsegnode(l,(l+r)>>1));
			nd.son[0]=++cnt;
    	}
    	if(!nd.son[1]){
			node.push_back(dsegnode(((l+r)>>1)+1,r));
			nd.son[1]=++cnt;
    	}
    	pushdown(now,l,r);
		update(l,(l+r)>>1,x,nd.son[0]);
		update(((l+r)>>1)+1,r,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e7+5e6+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){sum=t-s+1,tag=son[0]=son[1]=0;}
        void update(int x,int len){sum=len*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt,n,s,t;
    dsegtree(int nn){
    	n=nn;
    	node.resize(2);
    	node[1]=dsegnode(1,n);
    	cnt=root=1;
	}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now,int s,int t){
		if(nd.tag){
			ndl.update(nd.tag,(t+s)/2-s+1);
			ndr.update(nd.tag,t-((t+s)/2+1)+1);
			nd.tag=0;
		}
    }
    void update(int ss,int tt,int x){s=ss,t=tt,update(1,n,x,root);}
    void update(int l,int r,int x,int now){
    	if(s>r||t<l)return ;
    	if(s<=l&&t>=r) {
			nd.update(x,r-l+1);
			return ;
    	}
    	if(!nd.son[0]){
			node.push_back(l,(l+r)>>1);
			nd.son[0]=++cnt;
    	}
    	if(!nd.son[1]){
			node.push_back(((l+r)>>1)+1,r);
			nd.son[1]=++cnt;
    	}
    	pushdown(now,l,r);
		update(l,(l+r)>>1,x,nd.son[0]);
		update(((l+r)>>1)+1,r,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e7+5e6+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){sum=t-s+1,tag=son[0]=son[1]=0;}
        void update(int x,int len){sum=len*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt,n,s,t;
    dsegtree(int nn){
    	n=nn;
    	node.resize(2);
    	node[1]=dsegnode(1,n);
    	cnt=root=1;
	}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now,int s,int t){
		if(nd.tag){
			ndl.update(nd.tag,(t+s)/2-s+1);
			ndr.update(nd.tag,t-((t+s)/2+1)+1);
			nd.tag=0;
		}
    }
    void update(int ss,int tt,int x){s=ss,t=tt,update(1,n,x,root);}
    void update(int l,int r,int x,int now){
    	if(s>r||t<l)return ;
    	if(s<=l&&t>=r) {
			nd.update(x,r-l+1);
			return ;
    	}
    	if(!nd.son[0]){
			node.emplace_back(l,(l+r)>>1);
			nd.son[0]=++cnt;
    	}
    	if(!nd.son[1]){
			node.emplace_back(((l+r)>>1)+1,r);
			nd.son[1]=++cnt;
    	}
    	pushdown(now,l,r);
		update(l,(l+r)>>1,x,nd.son[0]);
		update(((l+r)>>1)+1,r,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e7+5e6+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int l,r,son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){l=s,r=t,sum=t-s+1,tag=son[0]=son[1]=0;}
        int mid(){return (r+l)>>1;}
        int len(){return r-l+1;}
        void update(int x){sum=len()*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt;
    dsegtree(int n,int size=maxn){node.resize(maxn);cnt=root=1;node[1]=dsegnode(1,n);}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now){
		if(nd.tag){
			ndl.update(nd.tag);
			ndr.update(nd.tag);
			nd.tag=0;
		}
    }
    void update(int s,int t,int x,int now=1){
    	if(s>nd.r||t<nd.l)return ;
    	if(s<=nd.l&&t>=nd.r) {
			nd.update(x);
			return ;
    	}
    	if(!nd.son[0]){
			node[++cnt]=dsegnode(nd.l,nd.mid());
			nd.son[0]=cnt;
    	}
    	if(!nd.son[1]){
			node[++cnt]=dsegnode(nd.mid()+1,nd.r);
			nd.son[1]=cnt;
    	}
    	pushdown(now);
		update(s,t,x,nd.son[0]);
		update(s,t,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e7+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int l,r,son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){l=s,r=t,sum=t-s+1,tag=son[0]=son[1]=0;}
        int mid(){return (r+l)>>1;}
        int len(){return r-l+1;}
        void update(int x){sum=len()*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt;
    dsegtree(int n,int size=maxn){node.resize(maxn);cnt=root=1;node[1]=dsegnode(1,n);}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now){
		if(nd.tag){
			ndl.update(nd.tag);
			ndr.update(nd.tag);
			nd.tag=0;
		}
    }
    void update(int s,int t,int x,int now=1){
    	if(s>nd.r||t<nd.l)return ;
    	if(s<=nd.l&&t>=nd.r) {
			nd.update(x);
			return ;
    	}
    	if(!nd.son[0]){
			node[++cnt]=dsegnode(nd.l,nd.mid());
			nd.son[0]=cnt;
    	}
    	if(!nd.son[1]){
			node[++cnt]=dsegnode(nd.mid()+1,nd.r);
			nd.son[1]=cnt;
    	}
    	pushdown(now);
		update(s,t,x,nd.son[0]);
		update(s,t,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;

class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int l,r,son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){l=s,r=t,sum=t-s+1,tag=son[0]=son[1]=0;}
        int mid(){return (r+l)>>1;}
        int len(){return r-l+1;}
        void update(int x){sum=len()*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt;
    dsegtree(int n){node.resize(2);cnt=root=1;node[1]=dsegnode(1,n);}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now){
		if(nd.tag){
			ndl.update(nd.tag);
			ndr.update(nd.tag);
			nd.tag=0;
		}
    }
    void update(int s,int t,ll x,int now=1){
    	if(s>nd.r||t<nd.l)return ;
    	if(s<=nd.l&&t>=nd.r) {
			nd.update(x);
			return ;
    	}
    	if(!nd.son[0]){
			nd.son[0]=++cnt;
			node.emplace_back(nd.l,nd.mid());
    	}
    	if(!nd.son[1]){
			nd.son[1]=++cnt;
			node.emplace_back(nd.mid()+1,nd.r);
    	}
    	pushdown(now);
		update(s,t,x,nd.son[0]);
		update(s,t,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e7+5e6+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){sum=t-s+1,tag=son[0]=son[1]=0;}
        void update(int x,int len){sum=len*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt,n,s,t;
    dsegtree(int nn){
    	n=nn;
    	node.resize(2);
    	node[1]=dsegnode(1,n);
    	cnt=root=1;
	}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now,int s,int t){
		if(nd.tag){
			ndl.update(nd.tag,(t+s)/2-s+1);
			ndr.update(nd.tag,t-((t+s)/2+1)+1);
			nd.tag=0;
		}
    }
    void update(int ss,int tt,int x){s=ss,t=tt,update(1,n,x,root);}
    void update(int l,int r,int x,int now){
    	if(s>r||t<l)return ;
    	if(s<=l&&t>=r) {
			nd.update(x,r-l+1);
			return ;
    	}
    	if(!nd.son[0]){
			node.push_back(dsegtree(l,(l+r)>>1));
			nd.son[0]=++cnt;
    	}
    	if(!nd.son[1]){
			node.push_back(dsegtree(((l+r)>>1)+1,r));
			nd.son[1]=++cnt;
    	}
    	pushdown(now,l,r);
		update(l,(l+r)>>1,x,nd.son[0]);
		update(((l+r)>>1)+1,r,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;

class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int l,r,son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){l=s,r=t,sum=t-s+1,tag=son[0]=son[1]=0;}
        int mid(){return (r+l)>>1;}
        int len(){return r-l+1;}
        void update(int x){sum=len()*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt;
    dsegtree(int n){node.resize(2);cnt=root=1;node[1]=dsegnode(1,n);}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now){
		if(nd.tag){
			ndl.update(nd.tag);
			ndr.update(nd.tag);
			nd.tag=0;
		}
    }
    void update(int s,int t,int x,int now=1){
    	if(s>nd.r||t<nd.l)return ;
    	if(s<=nd.l&&t>=nd.r) {
			nd.update(x);
			return ;
    	}
    	if(!nd.son[0]){
			nd.son[0]=++cnt;
			node.emplace_back(nd.l,nd.mid());
    	}
    	if(!nd.son[1]){
			nd.son[1]=++cnt;
			node.emplace_back(nd.mid()+1,nd.r);
    	}
    	pushdown(now);
		update(s,t,x,nd.son[0]);
		update(s,t,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e5+7,maxm=1e7+7;
const ll INF=0x3f3f3f3f3f3f3f;
class graph{public:
  struct edge{
    int from,to;ll cost;
    edge(int a,int b,ll c){from=a,to=b,cost=c;}
  };
  vector<vector<edge>> node;
  int ud=0;
  graph(int n=maxn,int f=0){node.resize(n+2);ud=f;}
  void add(int a,int b,int c=1){node[a].emplace_back(a,b,c);if(ud)node[b].emplace_back(b,a,c);}
};
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
  struct dsegnode {
    int son[2];ll val;
    dsegnode(){val=INF;}
    dsegnode(int x){son[0]=son[1]=0;}
    void update(ll x){val=x;}
  };
  vector<dsegnode> node;
  vector<int> root;
  int cnt,n,s,t,pos;
  dsegtree(int nn,int size=maxm){
    n=nn,cnt=0;
    node.resize(n<<2|3);
    root.resize(n);
  }
  void pushup(int now){nd.val=min(ndl.val,ndr.val);}
  void pushdown(int now){}
  void change(int p,ll x,int now){
    pos=p;
    if(!root[now]) root[now]=++cnt;
    update(1,n,x,root[now]);
  }
  void update(int l,int r,ll x,int now){
    if(pos>r||pos<l) return ;
    if(l==r){
      nd.update(x);
      return ;
    }
    if(!nd.son[0]) nd.son[0]=++cnt;
    if(!nd.son[1]) nd.son[1]=++cnt;
    pushdown(now);
    update(l,(l+r)>>1,x,nd.son[0]);
    update(((l+r)>>1)+1,r,x,nd.son[1]);
    pushup(now);
  }
  void unite(int a,int b){root[a]=merge(root[a],root[b]);}
  int merge(int a,int b){
    if(!a||!b) return a^b;
    int now=++cnt;
    nd.son[0]=merge(node[a].son[0],node[b].son[0]);
    nd.son[1]=merge(node[a].son[1],node[b].son[1]);
    nd.val=min(node[a].val,node[b].val);
    return now;
  }
  ll query(int ss,int tt,int now){s=ss,t=tt;return count(1,n,root[now]);}
  ll count(int l,int r,int now){
    if(s>r||t<l) return INF;
    if(s<=l&&t>=r) return nd.val;
    return min(count(l,(l+r)>>1,nd.son[0]),count(((l+r)>>1)+1,r,nd.son[1]));
  }
};
int main() {
  IO;
  ll n,m,root;
  cin>>n>>root;
  vector<int> dep(n+7,0);
  vector<ll> val(n+7);
  rep(i,1,n) cin>>val[i];
  graph g(n,1);
  register ll a,b;
  rep(i,2,n){
    cin>>a>>b;
    g.add(a,b);
  }
  dsegtree tree(n);
  auto dfs=[&tree,&g,&val,&dep](auto &&dfs,int now,int pre=-1,int dis=1)->void{
    dep[now]=dis;
    tree.change(dis,val[now],now);
    for(auto &i:g.node[now]){
      if(i.to==pre) continue;
      dfs(dfs,i.to,now,dis+1);
      tree.unite(now,i.to);
    }
  };
  dfs(dfs,root);
  cin>>m;
  ll x=0,last=0,k=0;
  while(m--){
    cin>>a>>b;
    x=(a+last)%n+1,k=(b+last)%n;
    last=tree.query(dep[x],dep[x]+k,x);
    cout<<last<<endl;
  }
  return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;++ii)
using namespace std;
int casn,n,m,k;
const int maxn=1e7+5e6+7;
class dsegtree{public:
#define nd  node[now]
#define ndl node[node[now].son[0]]
#define ndr node[node[now].son[1]]
    struct dsegnode {
        int son[2],tag,sum;
        dsegnode(){}
        dsegnode(int s,int t){sum=t-s+1,tag=son[0]=son[1]=0;}
        void update(int x,int len){sum=len*(x-1),tag=x;}
    };
    vector<dsegnode> node;
	int root,cnt,n,s,t;
    dsegtree(int nn,int size=maxn){
    	n=nn;
    	node.resize(maxn);
    	node[1]=dsegnode(1,n);
    	cnt=root=1;
	}
    void pushup(int now){nd.sum=ndl.sum+ndr.sum;}
    void pushdown(int now,int s,int t){
		if(nd.tag){
			ndl.update(nd.tag,(t+s)/2-s+1);
			ndr.update(nd.tag,t-((t+s)/2+1)+1);
			nd.tag=0;
		}
    }
    void update(int ss,int tt,int x){s=ss,t=tt,update(1,n,x,root);}
    void update(int l,int r,int x,int now){
    	if(s>r||t<l)return ;
    	if(s<=l&&t>=r) {
			nd.update(x,r-l+1);
			return ;
    	}
    	if(!nd.son[0]){
			node[++cnt]=dsegnode(l,(l+r)>>1);
			nd.son[0]=cnt;
    	}
    	if(!nd.son[1]){
			node[++cnt]=dsegnode(((l+r)>>1)+1,r);
			nd.son[1]=cnt;
    	}
    	pushdown(now,l,r);
		update(l,(l+r)>>1,x,nd.son[0]);
		update(((l+r)>>1)+1,r,x,nd.son[1]);
    	pushup(now);
    }
};

int main() {
	IO;
	ll n,m;
	cin>>n>>m;
	dsegtree tree(n);
	int a,b,c;
	while(m--){
		cin>>a>>b>>c;
		tree.update(a,b,c);
		cout<<tree.node[tree.root].sum<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
namespace fio {
	streambuf* in = cin.rdbuf();
	char bb[1000000], * s = bb, * t = bb;
#define gc() (s==t&&(t=(s=bb)+in->sgetn(bb,1000000),s==t)?EOF:*s++)
	inline int read() {
		int x = 0; char ch = gc();
		while (ch < 48)ch = gc();
		while (ch >= 48)x = x * 10 + ch - 48, ch = gc();
		return x;
	}
}using fio::read;
int n, m, k;
class kotree {
protected:
	class node {
	public:
		int l, r;
		bool val;
		bool operator < (const node ot)const {
			return l < ot.l;
		}
	};
	set<node>odt;
	auto split(int x) {
		auto nex = odt.lower_bound({ x,0,0 });
		if (nex != odt.end() && nex->l == x)return nex;
		nex--;
		int l = nex->l, r = nex->r;
		bool val = nex->val;
		odt.erase(nex), odt.insert({ l,x - 1,val });
		return odt.insert({ x,r,val }).first;
	}
	int ans;
public:
	kotree(int n = 0) { odt.clear(), odt.insert({ 1,n,1 }), ans = n; }
	void assign(int l, int r, bool val) {
		auto rb = split(r + 1), lb = split(l);
		ans += (r - l + 1) * val - sum(l, r);
		odt.erase(lb, rb), odt.insert({ l,r,val });
	}
	int sum(int l, int r) {
		auto rb = split(r + 1), lb = split(l);
		int ansx = 0;
		while (lb != rb)ansx += (int)lb->val * (lb->r - lb->l + 1), lb++;
		return ansx;
	}
	int total() { return ans; }
}ygy;
void w(int x) {
	if (x > 9)w(x / 10);
	putchar(x % 10 + 48);
}
int main() {
	n = read(), m = read();
	ygy = kotree(n);
	for (int i = 1; i <= m; i++) {
		int a = read(), b = read(), c = read();
		ygy.assign(a, b, (c - 1) != 0);
		w(ygy.total()), putchar('\n');
	}
}


#include<iostream>
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
using namespace std;
namespace fio {
	streambuf* in = cin.rdbuf();
	char bb[1000000], * s = bb, * t = bb;
#define gc() (s==t&&(t=(s=bb)+in->sgetn(bb,1000000),s==t)?EOF:*s++)
	inline int read() {
		int x = 0; char ch = gc();
		while (ch < 48)ch = gc();
		while (ch >= 48)x = x * 10 + ch - 48, ch = gc();
		return x;
	}
}using fio::read;
int n, m, k;
class kotree {
protected:
	class node {
	public:
		int l, r;
		bool val;
		bool operator < (const node ot)const {
			return l < ot.l;
		}
	};
	set<node>odt;
	auto split(int x) {
		auto nex = odt.lower_bound({ x,0,0 });
		if (nex != odt.end() && nex->l == x)return nex;
		nex--;
		int l = nex->l, r = nex->r;
		bool val = nex->val;
		odt.erase(nex), odt.insert({ l,x - 1,val });
		return odt.insert({ x,r,val }).first;
	}
public:
	kotree(int n = 0) { odt.clear(), odt.insert({ 1,n,1 }); }
	void assign(int l, int r, bool val) {
		auto rb = split(r + 1), lb = split(l);
		odt.erase(lb, rb), odt.insert({ l,r,val });
	}
	long long total() {
		long long ans = 0;
		for (node it : odt) //你们在这里也写auto那就过分了
			ans += (1ll * it.r - it.l + 1) * static_cast<long long>(it.val);
		return ans;
	}
}ygy;
int main() {
	n = read(), m = read();
	ygy = kotree(n);
	for (int i = 1; i <= m; i++) {
		int a = read(), b = read(), c = read();
		ygy.assign(a, b, (c - 1) != 0);
		cout << ygy.total() << endl;
	}
}