#include<bits/stdc++.h>
using namespace std;
//#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//    #pragma GCC target("avx,avx2,fma")
//    #pragma GCC optimization ("unroll-loops")
//#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define vec vector
#define s second
#define vi_a vector<int>a;
#define p_b push_back
#define pb push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define int long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (int)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)
//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
template<typename T> bool umax(T& a, T b) {return a<b?a=b,1:0;}
template<typename T> bool umin(T& a, T b) {return b<a?a=b,1:0;}
bool is_prime(ll val){for(ll i=2;i<=sqrt(val);i++)if(val%i==0)return 0; return 1;}
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll RR=1e4;
const ll tx[8]={1,-1,2,-2,-1,-2};
const ll ty[8]={-2,-2,-1,-1,2,1};
const char rev_to[4]={'E','W','N','S'};
const int M=1e9+7;
const int N=3e2+3;
const int ppp=73;
const int K=2e5+2;
const int block=600;
const int OPEN=1;
const int CLOSE=0;
//typedef pair<long long,int> pli;
//typedef tree<pli,null_type,less<pli>,rb_tree_tag,tree_order_statistics_node_update> o_st;
auto rnd=bind(uniform_int_distribution<int>(1,5969699),mt19937(time(0)));
void bad(){
    cout<<"IMPOSSIBLE";
    exit(0);
}
int dp[N];
bool used[N];
vec<int> g[N];
void recalc(int v,int p){
    dp[v]=1;
    for(auto &z : g[v]){
        if(used[z] || z==p) continue;
        recalc(z,v);
        dp[v]+=dp[z];
    }
}
int get_centroid(int v,int p,int sz){
//    debug()<<imie(dp[v]);
    for(auto &z : g[v]){
        if(!used[z] && z!=p && dp[z]>=(sz+1)/2){
            return get_centroid(z,v,sz);
        }
    }
    return v;
}
map<int,int>mp;
string s;
int masks[N];
void dfs(int v,int msk,int p,vec<int> &a){
    msk^=(1<<(s[v]-'a'));
    a.p_b(v);
    masks[v]=msk;
    for(auto &z : g[v]){
        if(used[z] || z==p) continue;
        dfs(z,msk,v,a);
    }
}
int get(int mask){
    int ans=0;
    if(__builtin_popcount(mask)==1){
        int j=0;
        for(j=0;j<26;j++){
            if(pw(j)&mask)
                break;
        }
        for(int i=0;i<26;i++){
            ans+=mp[(1<<i)^(1<<j)];
        }
    }
    else if(__builtin_popcount(mask)==0){
        ans=mp[0];
        for(int i=0;i<26;i++){
            ans+=mp[1<<i];
        }
    }
    return ans;
}
int ans[N];
int rans[N];
void upd_ans(int v,int p,vec<int> &a){
    a.p_b(v);
    for(auto &z : g[v]){
        if(!used[z] && z!=p){
            upd_ans(z,v,a);
                rans[v]+=rans[z];
        }
    }
}
void go(int v){
    mp.clear();
    recalc(v,v);
    v=get_centroid(v,v,dp[v]);
    used[v]=1;
    masks[v]=1<<(s[v]-'a');
    mp[1<<(s[v]-'a')]++;
    vec<int>c;
    rans[v]=0;
    for(auto &z : g[v]){
        if(used[z]) continue;
        dfs(z,0,v,c);
        for(auto &q : c){
            rans[q]+=get(masks[q]);
        }
        for(auto &q : c){
            mp[masks[q]^(1<<(s[v]-'a'))]++;
        }
        c.clear();
    }
    mp.clear();
    mp[1<<(s[v]-'a')]++;
    for(int i=sz(g[v])-1;i>=0;i--){
        auto z=g[v][i];
        if(used[z]) continue;
        dfs(z,0,v,c);
        for(auto &q : c){
            rans[q]+=get(masks[q]);
        }
        for(auto &q : c){
            mp[masks[q]^(1<<(s[v]-'a'))]++;
        }
         c.clear();
    }
    mp[1<<(s[v]-'a')]--;
    rans[v]+=get(0);
    upd_ans(v,v,c);
    for(auto &z : c){
        if(z^v)
            ans[z]+=rans[z];
        else
            ans[z]+=rans[z]/2;
        rans[z]=0;
    }
    for(auto &z : g[v])
        if(!used[z])
            go(z);
}
signed main()
{
    fast_io;
    int n;
    cin>>n;
    for(int i=1;i < n;i++){
        int v,u;
        cin >> v >> u;
        -- v; -- u;
        g[v].pb(u);
        g[u].pb(v);
    }
    cin>>s;
    go(0);
    for(int i = 0; i < n; ++i)
        cout<<ans[i]+1<<' ';
    return 0;
}
/*
15
999834725 999842153 999849581 999857009 999864437 999871865 999879293 999886721 999894149 999901577 999909005 999916433 999901579 999909005 999916431
*/


#include<bits/stdc++.h>
using namespace std;
//#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//    #pragma GCC target("avx,avx2,fma")
//    #pragma GCC optimization ("unroll-loops")
//#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define vec vector
#define s second
#define vi_a vector<int>a;
#define p_b push_back
#define pb push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define int long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (int)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)
//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
template<typename T> bool umax(T& a, T b) {return a<b?a=b,1:0;}
template<typename T> bool umin(T& a, T b) {return b<a?a=b,1:0;}
bool is_prime(ll val){for(ll i=2;i<=sqrt(val);i++)if(val%i==0)return 0; return 1;}
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll RR=1e4;
const ll tx[8]={1,-1,2,-2,-1,-2};
const ll ty[8]={-2,-2,-1,-1,2,1};
const char rev_to[4]={'E','W','N','S'};
const int M=1e9+7;
const int N=3e5+3;
const int ppp=73;
const int K=2e5+2;
const int block=600;
const int OPEN=1;
const int CLOSE=0;
//typedef pair<long long,int> pli;
//typedef tree<pli,null_type,less<pli>,rb_tree_tag,tree_order_statistics_node_update> o_st;
auto rnd=bind(uniform_int_distribution<int>(1,5969699),mt19937(time(0)));
void bad(){
    cout<<"IMPOSSIBLE";
    exit(0);
}
int dp[N];
bool used[N];
vec<int> g[N];
void recalc(int v,int p){
    dp[v]=1;
    for(auto &z : g[v]){
        if(used[z] || z==p) continue;
        recalc(z,v);
        dp[v]+=dp[z];
    }
}
int get_centroid(int v,int p,int sz){
    for(auto &z : g[v]){
        if(!used[z] && z!=p && dp[z]>=sz/2){
            return get_centroid(z,v,sz);
        }
    }
    return v;
}
map<int,int>mp;
string s;
int masks[N];
void dfs(int v,int msk,int p,vec<int> &a){
    msk^=(1<<(s[v]-'a'));
    a.p_b(v);
    masks[v]=msk;
    for(auto &z : g[v]){
        if(used[z] || z==p) continue;
        dfs(z,msk,v,a);
    }
}
int get(int mask){
    int ans=mp[mask];
    for(int i=0;i<26;i++){
            ans+=mp[(1<<i)^mask];
    }
    return ans;
}
ll ans[N];
ll rans[N];
void upd_ans(int v,int p,vec<int> &a){
    a.p_b(v);
    for(auto &z : g[v]){
        if(!used[z] && z!=p){
            upd_ans(z,v,a);
            rans[v]+=rans[z];
        }
    }
}
void go(int v){
    mp.clear();
    recalc(v,v);
    v=get_centroid(v,v,dp[v]);
    used[v]=1;
    masks[v]=1<<(s[v]-'a');
    mp[1<<(s[v]-'a')]++;
    vec<int>c;
    rans[v]=0;
//    debug()<<imie(v);
    for(auto &z : g[v]){
        if(used[z]) continue;
        dfs(z,0,v,c);
        for(auto &q : c){
            rans[q]+=get(masks[q]);
        }
        for(auto &q : c){
            mp[masks[q]^(1<<(s[v]-'a'))]++;
        }
        c.clear();
    }
    mp.clear();
    for(int i=sz(g[v])-1;i>=0;i--){
        auto z=g[v][i];
        if(used[z]) continue;
        dfs(z,0,v,c);
        for(auto &q : c){
            rans[q]+=get(masks[q]);
        }
        for(auto &q : c){
            mp[masks[q]^(1<<(s[v]-'a'))]++;
        }
        c.clear();
    }
    rans[v]+=get(0);
    upd_ans(v,v,c);

    for(auto &z : c){
        if(z^v)
            ans[z]+=rans[z];
        else
            ans[z]+=rans[z]/2,assert(rans[z]%2==0);
        rans[z]=0;
    }
    c.clear();
    for(auto &z : g[v])
        if(!used[z])
            go(z);
}
signed main()
{
    fast_io;
    int n;
    cin>>n;
    for(int i=1;i < n;i++){
        int v,u;
        cin >> v >> u;
        -- v; -- u;
        g[v].pb(u);
        g[u].pb(v);
    }
    cin>>s;
    go(0);
    for(int i = 0; i < n; ++i)
        cout<<ans[i]+1<<' ';
    return 0;
}
/*
15
999834725 999842153 999849581 999857009 999864437 999871865 999879293 999886721 999894149 999901577 999909005 999916433 999901579 999909005 999916431
*/


#include<bits/stdc++.h>
using namespace std;
const int Maxn=1005;
int n;
bool was[Maxn];
vector<int>a,b;
int main()
{
	int num;
	while(scanf("%d,",&num))
		was[num++];
	for(int i=0;i<Maxn;i++)
		if(was[i])
			if(!b.empty()&&b.back()==i-1)
				b.back()=i;
			else
			{
				a.push_back(i);
				b.push_back(i);
			}
	for(int i=0;i<a.size();i++){
		if(a[i]==b[i])printf("%d",a[i]);
		else printf("%d-%d",a[i],b[i]);
		printf("%s",i+1<a.size()?",":"/n");
	}
}


#include<cstdio>
#include<vector>
using namespace std;
const int Maxn=1005;
int n;
bool was[Maxn];
vector<int>a,b;
int main()
{
	int num;
	while(scanf("%d,",&num))
		was[num++];
	for(int i=0;i<Maxn;i++)
		if(was[i])
			if(!b.empty()&&b.back()==i-1)
				b.back()=i;
			else
			{
				a.push_back(i);
				b.push_back(i);
			}
	for(int i=0;i<a.size();i++){
		if(a[i]==b[i])printf("%d",a[i]);
		else printf("%d-%d",a[i],b[i]);
		printf("%s",i+1<a.size()?",":"/n");
	}
}


#include <bits/stdc++.h>

using namespace std;

set<int> s;
vector<pair<int,int> > v;

int main()
{
    int tmp;
    char tmp2;
    while(cin >> tmp)
    {
        cin >> tmp2;
        s.insert(tmp);
    }
    set<int>::iterator it;
    bool st=1;
    int l=0;
    pair<int,int> dum;
    int i;
    for(it=s.begin();it!=s.end();it++)
    {
        if(st)
        {
            dum.first=*it;
            l=*it;
            st=false;
            continue;
        }
        if(*it==l+1)
        {
            l=*it;
            continue;
        }
        else
        {
            dum.second=l;
            v.push_back(dum);
            st=true;
        }
    }
    for(i=0;i<v.size()-1;i++)
    {
        if(v[i].first==v[i].second)
        {
            cout << v[i].first << ",";
        }
        else
        {
            cout << v[i].first << "-" << v[i].second << ",";
        }
    }
    if(v[v.size()-1].first==v[v.size()-1].second)
        cout << v[v.size()-1].first << endl;
    else
        cout << v[v.size()-1].first << "-" << v[v.size()-1].second << endl;
}


#include <bits/stdc++.h>

using namespace std;

set<int> s;
vector<pair<int,int> > v;

int main()
{
    //freopen("pn.in","r",stdin);
    int tmp;
    char tmp2;
    while(cin >> tmp)
    {
        cin >> tmp2;
        s.insert(tmp);
    }
    set<int>::iterator it;
    bool st=1;
    int l=0;
    pair<int,int> dum;
    int i;
    for(it=s.begin();it!=s.end();it++)
    {
        //cout << *it << endl;
        if(st)
        {
            dum.first=*it;
            l=*it;
            it++;
            if(it==s.end())
            {
                dum.second=l;
                v.push_back(dum);
                break;
            }
            it--;
            st=false;
            continue;
        }
        if(*it==l+1)
        {
            l=*it;
            continue;
        }
        else
        {
            dum.second=l;
            v.push_back(dum);
            st=true;
            it--;
        }
    }
    for(i=0;i<v.size()-1;i++)
    {
        if(v[i].first==v[i].second)
        {
            cout << v[i].first << ",";
        }
        else
        {
            cout << v[i].first << "-" << v[i].second << ",";
        }
    }
    if(v[v.size()-1].first==v[v.size()-1].second)
        cout << v[v.size()-1].first << endl;
    else
        cout << v[v.size()-1].first << "-" << v[v.size()-1].second << endl;
}


#include <bits/stdc++.h>

using namespace std;

set<int> s;
vector<pair<int,int> > v;

int main()
{
    //freopen("pn.in","r",stdin);
    int tmp;
    char tmp2;
    while(cin >> tmp)
    {
        cin >> tmp2;
        s.insert(tmp);
    }
    set<int>::iterator it;
    bool st=1;
    int l=0;
    pair<int,int> dum;
    int i;
    for(it=s.begin();it!=s.end();it++)
    {
        /*cout << *it << endl;
        for(i=0;i<v.size();i++)
            cout << v[i].first << " " <<v[i].second << endl;;*/
        if(st)
        {
            dum.first=*it;
            l=*it;
            it++;
            if(it==s.end())
            {
                dum.second=l;
                v.push_back(dum);
                break;
            }
            it--;
            st=false;
            continue;
        }
        if(*it==l+1)
        {
            l=*it;
            it++;
            if(it==s.end())
            {
                dum.second=l;
                v.push_back(dum);
                break;
            }
            it--;
            continue;
        }
        else
        {
            dum.second=l;
            v.push_back(dum);
            st=true;
            it--;
        }
    }
    for(i=0;i<v.size()-1;i++)
    {
        if(v[i].first==v[i].second)
        {
            cout << v[i].first << ",";
        }
        else
        {
            cout << v[i].first << "-" << v[i].second << ",";
        }
    }
    if(v[v.size()-1].first==v[v.size()-1].second)
        cout << v[v.size()-1].first << endl;
    else
        cout << v[v.size()-1].first << "-" << v[v.size()-1].second << endl;
}


#include<stdio.h>
#include<iostream>
#include<set>
#include<string>
using namespace std;
set<int> s;
string a;
int main() {
	cin>>a;
	int z=0;
	while(1) {
		int where=a.find(",");
		if(where==a.npos) {
			string x=a.substr(z,a.size()-z);
			int y=0;
			for(int i=0; i<x.size(); i++) {
				y=y*10+x[i]-'0';
			}
			s.insert(y);
			break;
		}
		string x=a.substr(z,where-z);
		z=where+1;
		int y=0;
		for(int i=0; i<x.size(); i++) {
			y=y*10+x[i]-'0';
		}
		s.insert(y);
		a[where]='.';
	}
	int y=-233;
	int c[1001]= {0};
	for(set<int>::iterator it=s.begin(); it!=s.end(); ++it) {
		int x=*it;
		if(x==y+1) {
			if(c[y]<0) {
				int front=0-c[y];
				c[x]=c[y];
				c[front]++;
			} else {
				c[y]++;
				c[x]=0-y;
			}
		} else {
			c[x]=1;
		}
		y=x;
	}
	for(int i=1; i<=y; i++) {
		if(c[i]==1) {
			cout<<i;
			if(i!=y) {
				cout<<',';
			}
		}
		if(c[i]>1) {
			cout<<i<<'-'<<i+c[i]-1;
			if(i!=y) {
				cout<<',';
			}
		}
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<set>
#include<string>
using namespace std;
set<int> s;
string a;
int main() {
	cin>>a;
	int z=0;
	while(1) {
		int where=a.find(",");
		if(where==a.npos) {
			string x=a.substr(z,a.size()-z);
			int y=0;
			for(int i=0; i<x.size(); i++) {
				y=y*10+x[i]-'0';
			}
			s.insert(y);
			break;
		}
		string x=a.substr(z,where-z);
		z=where+1;
		int y=0;
		for(int i=0; i<x.size(); i++) {
			y=y*10+x[i]-'0';
		}
		s.insert(y);
		a[where]='.';
	}
	int y=-233;
	int c[1001]= {0};
	for(set<int>::iterator it=s.begin(); it!=s.end(); ++it) {
		int x=*it;
		if(x==y+1) {
			if(c[y]<0) {
				int front=0-c[y];
				c[x]=c[y];
				c[front]++;
			} else {
				c[y]++;
				c[x]=0-y;
			}
		} else {
			c[x]=1;
		}
		y=x;
	}
	for(int i=1; i<=y; i++) {
		if(c[i]==1) {
			cout<<i;
			if(i!=y) {
				cout<<',';
			}
		}
		if(c[i]>1) {
			cout<<i<<'-'<<i+c[i]-1;
			if(i!=y) {
				cout<<',';
			}
		}
	}
	return 0;
}
/*
1,1,1,1,1,1,12,3,3,3,4,1000
*/


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define ll long long
#define maxn 116
#define pp pair<int,int>
#define INF 0x3f3f3f3f
#define max(x,y) ( ((x) > (y)) ? (x) : (y) )
#define min(x,y) ( ((x) > (y)) ? (y) : (x) )
using namespace std;
char str[10100];
int main() {

	while(~scanf("%s",str)) {
		set <int> s;
		int tem;
		char sb[6];
		for(int i=0; i<=strlen(str); i++) {
			if(str[i]==','||str[i]=='\0') {
				int p=0,q=i;
				while((--q)>=0&&str[q]!=',')sb[p++]=str[q];
				sb[p]='\0';
				strrev(sb);
				sscanf(sb,"%d",&tem);
				s.insert(tem);
			}
		}
		vector <int> a(s.begin(),s.end());
		int ansx[1010],ansy[1010],p=0;
		for(int i=0; i<a.size()-1; i++) {
			int pos=i;
			while(i+1<a.size()&&a[i]+1==a[i+1])
				i++;
			ansx[p]=a[pos];
			ansy[p++]=a[i];
		}
		if(ansy[p-1]!=a[a.size()-1]) {
			ansx[p]=a[a.size()-1];
			ansy[p++]=a[a.size()-1];
		}
		for(int i=0; i<p; i++) {
			if(i!=p-1) {
				if(ansx[i]==ansy[i])
					printf("%d,",ansx[i]);
				else
					printf("%d-%d,",ansx[i],ansy[i]);
			} else {
				if(ansx[i]==ansy[i])
					printf("%d\n",ansx[i]);
				else
					printf("%d-%d\n",ansx[i],ansy[i]);
			}
		}
	}
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<set>
#include<string>
using namespace std;
set<int> s;
string a;
int main() {
	cin>>a;
	int z=0;
	while(1) {
		int where=a.find(",");
		if(where==a.npos) {
			string x=a.substr(z,a.size()-z);
			int y=0;
			for(int i=0; i<x.size(); i++) {
				y=y*10+x[i]-'0';
			}
			s.insert(y);
			break;
		}
		string x=a.substr(z,where-z);
		z=where+1;
		int y=0;
		for(int i=0; i<x.size(); i++) {
			y=y*10+x[i]-'0';
		}
		s.insert(y);
		a[where]='.';
	}
	int y=-233;
	int zz=0;
	int c[1001]= {0};
	for(set<int>::iterator it=s.begin(); it!=s.end(); ++it) {
		int x=*it;
		if(x==y+1) {
			if(c[y]<0) {
				int front=0-c[y];
				c[x]=c[y];
				c[front]++;
				zz=front;
			} else {
				c[y]++;
				c[x]=0-y;
				zz=y;
			}
		} else {
			c[x]=1;
			zz=x;
		}
		y=x;
	}
	for(int i=1; i<=zz; i++) {
		if(c[i]==1) {
			cout<<i;
			if(i!=zz) {
				cout<<',';
			}
		}
		if(c[i]>1) {
			cout<<i<<'-'<<i+c[i]-1;
			if(i!=zz) {
				cout<<',';
			}
		}
	}
	return 0;
}
/*
300,302,20,100,10,1,301
*/


//By Abdurazzacov Yerzhan
// email address : erjan1996-96@mail.ru
// email address : erzhan96@mail.ru
// email address : erjan1996@gmail.ru
//telephone number : 8-702-818-66-12
 /* Allah Saktasin */
//C++ headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cassert>
#include<climits>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<clocale>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>

//containers
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<complex>
#include<string>
#include<stack>
#include<bitset>
#include<istream>
#include<valarray>

//IOs
#include<iostream>
#include<sstream>
#include<iomanip>
#include<fstream>
#include<exception>
#include<ios>
#include<iosfwd>
#include<ostream>
#include<iterator>
#include<stdexcept>
#include<streambuf>

//algorithm & miscellaneous
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<limits>
#include<locale>
#include<memory>
#include<new>

/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/---Frequently used macros---\_/\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */

#define MOD 1000000007
#define INF 1000000000

/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/\_/\_/---Shorthands---\_/\_/\_/\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */

using namespace std;

typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef long long ll;
typedef set < int >::iterator sii;
typedef deque < int > di;

#define F first
#define S second

#define s( x ) scanf ( "%d" , &x )
#define sl( x ) scanf ( "%lld" , &x )
#define ss( x ) scanf ( "%s" , &x )

#define p(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define ps(x) printf("%s",x)

#define pn(x) printf("%d\n",x)
#define pln(x) printf("%lld\n",x)
#define psn(x) printf("%s\n",x)

#define X length()
#define mp make_pair
#define pub(x) push_back(x)
#define puf(x) push_front(x)
#define pob() pop_back()
#define pof() pop_front()
#define forn(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define ford(i, n) for(ll i = (ll)(n) ; i >= 1; i--)
#define fore(i, a, n) for(ll i = (ll)(a); i < (ll)(n); i++)

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

ll x , a[ 1001 ] , c = 1 , b[ 1001 ];
char ch;

  int main ()
{

  #ifndef ONLINE_JUDGE
    freopen ( "input.txt" , "rt" , stdin );
   freopen ( "output.txt" , "wt" , stdout );
  #endif

  memset ( a , 0 , sizeof ( a ) );
 while ( cin >> x  )
 {
  cin >> ch;
  a[ x ] = 1;
 }
 forn ( i , 1001 )
 {
    if ( a[ i ] == 1 && i != 1001 ) b[ c ] = i , c ++;
 }
 c --;
 forn ( i , c )
 {
    ll l = b[ i ] , in = i;
    while ( 1 )
    {
        if ( b[ in ] + 1 == b[ in + 1 ] ) in ++;
        else break;
    }
    if ( in != i ) cout << l << '-' << b[ in ] , i = in;
    else cout << l;
    if ( i < c ) cout << ',';
 }

fclose ( stdin );
fclose ( stdout );
}


//By Abdurazzacov Yerzhan
// email address : erjan1996-96@mail.ru
// email address : erzhan96@mail.ru
// email address : erjan1996@gmail.ru
//telephone number : 8-702-818-66-12
 /* Allah Saktasin */
//C++ headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cassert>
#include<climits>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<clocale>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>

//containers
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<complex>
#include<string>
#include<stack>
#include<bitset>
#include<istream>
#include<valarray>

//IOs
#include<iostream>
#include<sstream>
#include<iomanip>
#include<fstream>
#include<exception>
#include<ios>
#include<iosfwd>
#include<ostream>
#include<iterator>
#include<stdexcept>
#include<streambuf>

//algorithm & miscellaneous
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<limits>
#include<locale>
#include<memory>
#include<new>

/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/---Frequently used macros---\_/\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */

#define MOD 1000000007
#define INF 1000000000

/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/\_/\_/---Shorthands---\_/\_/\_/\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */

using namespace std;

typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef long long ll;
typedef set < int >::iterator sii;
typedef deque < int > di;

#define F first
#define S second

#define s( x ) scanf ( "%d" , &x )
#define sl( x ) scanf ( "%lld" , &x )
#define ss( x ) scanf ( "%s" , &x )

#define p(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define ps(x) printf("%s",x)

#define pn(x) printf("%d\n",x)
#define pln(x) printf("%lld\n",x)
#define psn(x) printf("%s\n",x)

#define X length()
#define mp make_pair
#define pub(x) push_back(x)
#define puf(x) push_front(x)
#define pob() pop_back()
#define pof() pop_front()
#define forn(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define ford(i, n) for(ll i = (ll)(n) ; i >= 1; i--)
#define fore(i, a, n) for(ll i = (ll)(a); i < (ll)(n); i++)

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

ll x , a[ 1000 ] , c = 1 , b[ 1000 ];
char ch;

  int main ()
{

  #ifndef ONLINE_JUDGE
    freopen ( "input.txt" , "rt" , stdin );
   freopen ( "output.txt" , "wt" , stdout );
  #endif

 while ( cin >> x  )
 {
  cin >> ch;
  a[ x ] = 1;
 }
 forn ( i , 1000 )
 {
    if ( a[ i ] == 1 ) b[ c ] = i , c ++;
 }
 c --;
 forn ( i , c )
 {
    ll l = b[ i ] , in = i;
    while ( 1 )
    {
        if ( b[ in ] + 1 == b[ in + 1 ] ) in ++;
        else break;
    }
    if ( in != i ) cout << l << '-' << b[ in ] , i = in;
    else cout << l;
    if ( i < c ) cout << ',';
 }

fclose ( stdin );
fclose ( stdout );
}


//By Abdurazzacov Yerzhan
// email address : erjan1996-96@mail.ru
// email address : erzhan96@mail.ru
// email address : erjan1996@gmail.ru
//telephone number : 8-702-818-66-12
 /* Allah Saktasin */
//C++ headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cassert>
#include<climits>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<clocale>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>

//containers
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<complex>
#include<string>
#include<stack>
#include<bitset>
#include<istream>
#include<valarray>

//IOs
#include<iostream>
#include<sstream>
#include<iomanip>
#include<fstream>
#include<exception>
#include<ios>
#include<iosfwd>
#include<ostream>
#include<iterator>
#include<stdexcept>
#include<streambuf>

//algorithm & miscellaneous
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<limits>
#include<locale>
#include<memory>
#include<new>

/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/---Frequently used macros---\_/\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */

#define MOD 1000000007
#define INF 1000000000

/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/\_/\_/---Shorthands---\_/\_/\_/\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */

using namespace std;

typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef long long ll;
typedef set < int >::iterator sii;
typedef deque < int > di;

#define F first
#define S second

#define s( x ) scanf ( "%d" , &x )
#define sl( x ) scanf ( "%lld" , &x )
#define ss( x ) scanf ( "%s" , &x )

#define p(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define ps(x) printf("%s",x)

#define pn(x) printf("%d\n",x)
#define pln(x) printf("%lld\n",x)
#define psn(x) printf("%s\n",x)

#define X length()
#define mp make_pair
#define pub(x) push_back(x)
#define puf(x) push_front(x)
#define pob() pop_back()
#define pof() pop_front()
#define forn(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define ford(i, n) for(ll i = (ll)(n) ; i >= 1; i--)
#define fore(i, a, n) for(ll i = (ll)(a); i < (ll)(n); i++)

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

ll x , a[ 1001 ] , c = 1 , b[ 1001 ];
char ch;

  int main ()
{

  #ifndef ONLINE_JUDGE
    freopen ( "input.txt" , "rt" , stdin );
   freopen ( "output.txt" , "wt" , stdout );
  #endif

  memset ( a , 0 , sizeof ( a ) );
 while ( cin >> x  )
 {
  cin >> ch;
  a[ x ] = 1;
 }
 forn ( i , 1001 )
 {
    if ( a[ i ] == 1 ) b[ c ] = i , c ++;
 }
 c --;
 forn ( i , c )
 {
    ll l = b[ i ] , in = i;
    while ( 1 )
    {
        if ( b[ in ] + 1 == b[ in + 1 ] ) in ++;
        else break;
    }
    if ( in != i ) cout << l << '-' << b[ in ] , i = in;
    else cout << l;
    if ( i < c ) cout << ',';
 }

fclose ( stdin );
fclose ( stdout );
}


//By Abdurazzacov Yerzhan
// email address : erjan1996-96@mail.ru
// email address : erzhan96@mail.ru
// email address : erjan1996@gmail.ru
//telephone number : 8-702-818-66-12
 /* Allah Saktasin */
//C++ headers
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<cassert>
#include<climits>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<clocale>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>

//containers
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<complex>
#include<string>
#include<stack>
#include<bitset>
#include<istream>
#include<valarray>

//IOs
#include<iostream>
#include<sstream>
#include<iomanip>
#include<fstream>
#include<exception>
#include<ios>
#include<iosfwd>
#include<ostream>
#include<iterator>
#include<stdexcept>
#include<streambuf>

//algorithm & miscellaneous
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<limits>
#include<locale>
#include<memory>
#include<new>

/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/---Frequently used macros---\_/\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */

#define MOD 1000000007
#define INF 1000000000

/* ****************************************************************** */
// \_/\_/\_/\_/\_/\_/\_/\_/\_/---Shorthands---\_/\_/\_/\_/\_/\_/\_/\_/\_/
/* ****************************************************************** */

using namespace std;

typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef long long ll;
typedef set < int >::iterator sii;
typedef deque < int > di;

#define F first
#define S second

#define s( x ) scanf ( "%d" , &x )
#define sl( x ) scanf ( "%lld" , &x )
#define ss( x ) scanf ( "%s" , &x )

#define p(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define ps(x) printf("%s",x)

#define pn(x) printf("%d\n",x)
#define pln(x) printf("%lld\n",x)
#define psn(x) printf("%s\n",x)

#define X length()
#define mp make_pair
#define pub(x) push_back(x)
#define puf(x) push_front(x)
#define pob() pop_back()
#define pof() pop_front()
#define forn(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define ford(i, n) for(ll i = (ll)(n) ; i >= 1; i--)
#define fore(i, a, n) for(ll i = (ll)(a); i < (ll)(n); i++)

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

ll x , a[ 1000 ] , c = 1 , b[ 1000 ];
char ch;

  int main ()
{

  #ifndef ONLINE_JUDGE
    freopen ( "input.txt" , "rt" , stdin );
   freopen ( "output.txt" , "wt" , stdout );
  #endif

  memset ( a , 0 , sizeof ( a ) );
 while ( cin >> x  )
 {
  cin >> ch;
  a[ x ] = 1;
 }
 forn ( i , 1000 )
 {
    if ( a[ i ] == 1 ) b[ c ] = i , c ++;
 }
 c --;
 forn ( i , c )
 {
    ll l = b[ i ] , in = i;
    while ( 1 )
    {
        if ( b[ in ] + 1 == b[ in + 1 ] ) in ++;
        else break;
    }
    if ( in != i ) cout << l << '-' << b[ in ] , i = in;
    else cout << l;
    if ( i < c ) cout << ',';
 }

fclose ( stdin );
fclose ( stdout );
}


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

int data[1005];

int main()
{
    int n=0;
    char ch;
    while(scanf("%d",&data[n++])!=EOF)
    {
        cin>>ch;
    }
    n--;
        sort(data,data+n);
        int k=1;
        for(int i=1;i<n;i++)
        {
            if(data[i]!=data[i-1])
               data[k++]=data[i];
        }
        int s=0;
        int flag=0;
        for(int i=1;i<=k;i++)
        {
            if(data[i]-data[i-1]==1)
              continue;
            else
            {
                //s=i;
                flag=1;
                if(s==0)
                  if(i-1==s)printf("%d",data[s]);
                  else printf("%d-%d",data[s],data[i-1]);
                else
                  if(i-1==s)printf(",%d",data[s]);
                  else printf(",%d-%d",data[s],data[i-1]);
                s=i;
            }
        }
        if(flag==0) printf("%d-%d",data[0],data[k-1]);
        printf("\n");
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;

int data[1005];

int main()
{
    int n=0;
    char ch;
    while(scanf("%d",&data[n++])!=EOF)
    {
        cin>>ch;
    }
    n--;
        sort(data,data+n);
        int k=1;
        for(int i=1;i<n;i++)
        {
            if(data[i]!=data[i-1])
               data[k++]=data[i];
        }
        int s=0;
        int flag=0;
        for(int i=1;i<=k;i++)
        {
            if(data[i]-data[i-1]==1)
              continue;
            else
            {
                flag=1;
                if(s==0)
                  if(i-1==s)printf("%d",data[s]);
                  else printf("%d-%d",data[s],data[i-1]);
                else
                  if(i-1==s)printf(",%d",data[s]);
                  else printf(",%d-%d",data[s],data[i-1]);
                s=i;
            }
        }
        if(flag==0) printf("%d-%d",data[0],data[k-1]);
        printf("\n");
    return 0;
}


#include<iostream>
#include<sstream>
#include<string>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<set>
#include<bitset>
#include<algorithm>
#include<list>
#include<utility>
#include<functional>
#include <deque>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <ctime>

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>

using namespace std;

#define deb(a)      cout<<" -> "<<#a<<"  "<<a<<endl;
#define oo          (1<<30)
#define PI          3.141592653589793
#define pi          2*acos(0)
#define ERR         1e-5
#define PRE         1e-8
#define popcount(a) (__builtin_popcount(a))
#define SZ(a)       ((int)a.size())
#define PB          push_back
#define LL          long long
#define ISS         istringstream
#define OSS         ostringstream
#define SS          stringstream
#define VS          vector<string>
#define VI          vector<int>
#define VD          vector<double>
#define VLL         vector<long long>
#define SII         set<int>::iterator
#define SI          set<int>
#define mem(a,b)    memset(a,b,sizeof(a))
#define memc(a,b)   memcpy(a,b,sizeof(b))
#define fi(i,a,b)   for(i=a;i<b;i++)
#define fd(i,a,b)   for(i=a;i>b;i--)
#define fii(a,b)    for(i=a;i<b;i++)
#define fdi(a,b)    for(i=a;i>b;i--)
#define fij(a,b)    for(j=a;j<b;j++)
#define fdj(a,b)    for(j=a;j>b;j--)
#define fik(a,b)    for(k=a;k<b;k++)
#define fdk(a,b)    for(k=a;k>b;k--)
#define fil(a,b)    for(l=a;l<b;l++)
#define fdl(a,b)    for(l=a;l>b;l--)
#define ri(i,a)     for(i=0;i<a;i++)
#define rd(i,a)     for(i=a;i>-1;i--)
#define rii(a)      for(i=0;i<a;i++)
#define rdi(a)      for(i=a;i>-1;i--)
#define rij(a)      for(j=0;j<a;j++)
#define rdj(a)      for(j=a;j>-1;j--)
#define rik(a)      for(k=0;k<a;k++)
#define rdk(a)      for(k=a;k>-1;k--)
#define ril(a)      for(l=0;l<a;l++)
#define rdl(a)      for(l=a;i>-1;l--)
#define EQ(a,b)     (fabs(a-b)<ERR)
#define all(a)      (a).begin(),(a).end()
#define CROSS(a,b,c,d)  ((b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y))
#define sqr(a)      ((a)*(a))
#define p2(a)       (1LL<<a)

char str[10000];
int a[10000];

int main()
{
    //freopen("C.in","r",stdin);
    //freopen("out.in","w",stdout);
    int i,j,k,n,c;
    while(gets(str))
    {
        SS ss;
        for(i=0;str[i];i++)
            if(str[i]==',') str[i]=' ';
        c=0;
        ss<<str;
        n=0;
        while(ss>>a[n])
        {
        //    cout<<a[n]<<endl;
            n++;
        }

        sort(a,a+n);
        a[n] = 1000000;
        printf("%d",a[0]);
        k=a[0];
        j=0;

        for(i=1;i<n+1;i++)
        {
            if(a[i]>a[i-1]+1 && a[i-1]!=k)
            {

                if(j)   printf("-");
                else printf(",");

                printf("%d",a[i-1]);
                k=a[i-1];

                j=0;
            }
            else if(a[i] == a[i-1]+1)    j++;

        }

        printf("\n");
    }

    return 0;
}


#include<iostream>
#include<sstream>
#include<string>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<set>
#include<bitset>
#include<algorithm>
#include<list>
#include<utility>
#include<functional>
#include <deque>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <ctime>

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>

using namespace std;

#define deb(a)      cout<<" -> "<<#a<<"  "<<a<<endl;
#define oo          (1<<30)
#define PI          3.141592653589793
#define pi          2*acos(0)
#define ERR         1e-5
#define PRE         1e-8
#define popcount(a) (__builtin_popcount(a))
#define SZ(a)       ((int)a.size())
#define PB          push_back
#define LL          long long
#define ISS         istringstream
#define OSS         ostringstream
#define SS          stringstream
#define VS          vector<string>
#define VI          vector<int>
#define VD          vector<double>
#define VLL         vector<long long>
#define SII         set<int>::iterator
#define SI          set<int>
#define mem(a,b)    memset(a,b,sizeof(a))
#define memc(a,b)   memcpy(a,b,sizeof(b))
#define fi(i,a,b)   for(i=a;i<b;i++)
#define fd(i,a,b)   for(i=a;i>b;i--)
#define fii(a,b)    for(i=a;i<b;i++)
#define fdi(a,b)    for(i=a;i>b;i--)
#define fij(a,b)    for(j=a;j<b;j++)
#define fdj(a,b)    for(j=a;j>b;j--)
#define fik(a,b)    for(k=a;k<b;k++)
#define fdk(a,b)    for(k=a;k>b;k--)
#define fil(a,b)    for(l=a;l<b;l++)
#define fdl(a,b)    for(l=a;l>b;l--)
#define ri(i,a)     for(i=0;i<a;i++)
#define rd(i,a)     for(i=a;i>-1;i--)
#define rii(a)      for(i=0;i<a;i++)
#define rdi(a)      for(i=a;i>-1;i--)
#define rij(a)      for(j=0;j<a;j++)
#define rdj(a)      for(j=a;j>-1;j--)
#define rik(a)      for(k=0;k<a;k++)
#define rdk(a)      for(k=a;k>-1;k--)
#define ril(a)      for(l=0;l<a;l++)
#define rdl(a)      for(l=a;i>-1;l--)
#define EQ(a,b)     (fabs(a-b)<ERR)
#define all(a)      (a).begin(),(a).end()
#define CROSS(a,b,c,d)  ((b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y))
#define sqr(a)      ((a)*(a))
#define p2(a)       (1LL<<a)

char str[10000];

int main()
{
    //freopen("C.in","r",stdin);
    //freopen("out.in","w",stdout);
    int i,j,k,n,c;
    while(gets(str))
    {
        set<int>st;
        SS ss;
        for(i=0;str[i];i++)
            if(str[i]==',') str[i]=' ';
        c=0;
        ss<<str;
        n=0;
        while(ss>>k)
            st.insert(k);

        k=-1;
        c=0;
        for(set<int>::iterator I=st.begin();I!=st.end();)
        {
            if(c)   printf(",");
            printf("%d",*I);
            k=*I;
            c=1;
            j=0;
            I++;
            while(k+1==*I && I!=st.end())
            {
                k++;
                j++;
                I++;
            }
            if(j)
                printf("-%d",k);

        }
        printf("\n");
    }

    return 0;
}


#include<iostream>
#include<sstream>
#include<string>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<set>
#include<bitset>
#include<algorithm>
#include<list>
#include<utility>
#include<functional>
#include <deque>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <ctime>

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>

using namespace std;

#define deb(a)      cout<<" -> "<<#a<<"  "<<a<<endl;
#define oo          (1<<30)
#define PI          3.141592653589793
#define pi          2*acos(0)
#define ERR         1e-5
#define PRE         1e-8
#define popcount(a) (__builtin_popcount(a))
#define SZ(a)       ((int)a.size())
#define PB          push_back
#define LL          long long
#define ISS         istringstream
#define OSS         ostringstream
#define SS          stringstream
#define VS          vector<string>
#define VI          vector<int>
#define VD          vector<double>
#define VLL         vector<long long>
#define SII         set<int>::iterator
#define SI          set<int>
#define mem(a,b)    memset(a,b,sizeof(a))
#define memc(a,b)   memcpy(a,b,sizeof(b))
#define fi(i,a,b)   for(i=a;i<b;i++)
#define fd(i,a,b)   for(i=a;i>b;i--)
#define fii(a,b)    for(i=a;i<b;i++)
#define fdi(a,b)    for(i=a;i>b;i--)
#define fij(a,b)    for(j=a;j<b;j++)
#define fdj(a,b)    for(j=a;j>b;j--)
#define fik(a,b)    for(k=a;k<b;k++)
#define fdk(a,b)    for(k=a;k>b;k--)
#define fil(a,b)    for(l=a;l<b;l++)
#define fdl(a,b)    for(l=a;l>b;l--)
#define ri(i,a)     for(i=0;i<a;i++)
#define rd(i,a)     for(i=a;i>-1;i--)
#define rii(a)      for(i=0;i<a;i++)
#define rdi(a)      for(i=a;i>-1;i--)
#define rij(a)      for(j=0;j<a;j++)
#define rdj(a)      for(j=a;j>-1;j--)
#define rik(a)      for(k=0;k<a;k++)
#define rdk(a)      for(k=a;k>-1;k--)
#define ril(a)      for(l=0;l<a;l++)
#define rdl(a)      for(l=a;i>-1;l--)
#define EQ(a,b)     (fabs(a-b)<ERR)
#define all(a)      (a).begin(),(a).end()
#define CROSS(a,b,c,d)  ((b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y))
#define sqr(a)      ((a)*(a))
#define p2(a)       (1LL<<a)

char str[10000];
int a[10000];
int main()
{
    //freopen("C.in","r",stdin);
    //freopen("out.in","w",stdout);
    int i,j,k,n,c;
    while(gets(str))
    {
        SS ss;
        for(i=0;str[i];i++)
            if(str[i]==',') str[i]=' ';
        c=0;
        ss<<str;
        n=0;
        while(ss>>a[n])
        {
        //    cout<<a[n]<<endl;
            n++;
        }

        sort(a,a+n);
        a[n] = 1000000;
        printf("%d",a[0]);
        k=a[0];
        j=0;

        for(i=1;i<n+1;i++)
        {
            if(a[i]>a[i-1]+1 && a[i-1]!=k)
            {

                if(j>1)   printf("-");
                else printf(",");

                printf("%d",a[i-1]);
                k=a[i-1];

                j=0;
            }
            else if(a[i] == a[i-1]+1)    j++;

        }

        printf("\n");
    }

    return 0;
}


#include<iostream>
#include<sstream>
#include<string>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cctype>
#include<set>
#include<bitset>
#include<algorithm>
#include<list>
#include<utility>
#include<functional>
#include <deque>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <ctime>

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>

using namespace std;

#define deb(a)      cout<<" -> "<<#a<<"  "<<a<<endl;
#define oo          (1<<30)
#define PI          3.141592653589793
#define pi          2*acos(0)
#define ERR         1e-5
#define PRE         1e-8
#define popcount(a) (__builtin_popcount(a))
#define SZ(a)       ((int)a.size())
#define PB          push_back
#define LL          long long
#define ISS         istringstream
#define OSS         ostringstream
#define SS          stringstream
#define VS          vector<string>
#define VI          vector<int>
#define VD          vector<double>
#define VLL         vector<long long>
#define SII         set<int>::iterator
#define SI          set<int>
#define mem(a,b)    memset(a,b,sizeof(a))
#define memc(a,b)   memcpy(a,b,sizeof(b))
#define fi(i,a,b)   for(i=a;i<b;i++)
#define fd(i,a,b)   for(i=a;i>b;i--)
#define fii(a,b)    for(i=a;i<b;i++)
#define fdi(a,b)    for(i=a;i>b;i--)
#define fij(a,b)    for(j=a;j<b;j++)
#define fdj(a,b)    for(j=a;j>b;j--)
#define fik(a,b)    for(k=a;k<b;k++)
#define fdk(a,b)    for(k=a;k>b;k--)
#define fil(a,b)    for(l=a;l<b;l++)
#define fdl(a,b)    for(l=a;l>b;l--)
#define ri(i,a)     for(i=0;i<a;i++)
#define rd(i,a)     for(i=a;i>-1;i--)
#define rii(a)      for(i=0;i<a;i++)
#define rdi(a)      for(i=a;i>-1;i--)
#define rij(a)      for(j=0;j<a;j++)
#define rdj(a)      for(j=a;j>-1;j--)
#define rik(a)      for(k=0;k<a;k++)
#define rdk(a)      for(k=a;k>-1;k--)
#define ril(a)      for(l=0;l<a;l++)
#define rdl(a)      for(l=a;i>-1;l--)
#define EQ(a,b)     (fabs(a-b)<ERR)
#define all(a)      (a).begin(),(a).end()
#define CROSS(a,b,c,d)  ((b.x-a.x)*(d.y-c.y)-(d.x-c.x)*(b.y-a.y))
#define sqr(a)      ((a)*(a))
#define p2(a)       (1LL<<a)

char str[10000];

int main()
{
    //freopen("C.in","r",stdin);
    //freopen("out.in","w",stdout);
    int i,j,k,n,c;
    while(gets(str))
    {
        set<int>st;
        SS ss;
        for(i=0;str[i];i++)
            if(str[i]==',') str[i]=' ';
        c=0;
        ss<<str;
        n=0;
        while(ss>>k)
            st.insert(k);

        k=-1;
        c=0;
        for(set<int>::iterator I=st.begin();I!=st.end();)
        {
            if(c)   printf(",");
            printf("%d",*I);
            k=*I;
            c=1;
            j=0;
            while((k==*I || k+1==*I) && I!=st.end())
            {
                if(k+1==*I)
                {
                    k++;
                    j++;
                }
                I++;
            }
            if(j)
            printf("-%d",k);

        }

        printf("\n");
    }

    return 0;
}


#include <string>
#include <iostream>
#include <cstdio>
#include <math.h>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

int main()
{
    char s[1010];
    int a[1010];
    memset(a, 0, sizeof(a));

    scanf("%s", s);

    int i, j;
    int len;
    len=strlen(s);
    int mm=-1;

    int dd, ff;

    for(i=0; i<len; )
    {
        ff=0;
        while(s[i]!=',' && i<len)
        {
            dd=s[i]-48;
            ff=ff*10+dd;
            i++;
        }
        a[ff]=1;
        if(ff>mm)
          mm=ff;
        i++;
    }
    int flag=1;
    int q, w, pos;
    for(i=0;i<=mm; )
    {
        if(a[i]==1)
        {
            q=i;
            while(a[i]==1)
            {
                i++;
            }
            pos=i-1;
            if(pos==q)
            {
                if(flag==1)
                {
                    cout<<q;
                    flag=0;
                }
                else
                {
                    cout<<','<<q;
                }
            }
            else
            {
                if(flag==1)
                {
                    cout<<q<<'-'<<pos;
                    flag=0;
                }
                else
                {
                    cout<<','<<q<<'-'<<pos;
                }
            }
        }
        while(a[i]==0 && i<=mm )
        {
            i++;
        }
    }
    /*for(i=0; i<10; i++)
    {
        if(a[i]==1)
          cout<<i<<"***";
    }
    cout<<endl;  */

    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct node
{
    int from,to;
} q[10000];
int main()
{
    int a[1010];
    char s[10010];
    int p1,p2,e,t;
    while(gets(s)!=NULL)
    {
        memset(q,0,sizeof(q));
        int sum=0,k=0;
        e=0;
        t=0;
        memset(a,0,sizeof(a));
        int len=strlen(s);
        for(int i=0; i<len; i++)
        {
            if(s[i]>='0'&&s[i]<='9')
            {
                sum=sum*10+s[i]-'0';
            }
            else if(s[i]==',')
            {
                a[sum]=1;
                sum=0;
            }
        }
        a[sum]=1;
        int r=0;
        for(int i=1; i<=1009; i++)
        {
            if(a[i]&&e==0)
            {
                p1=i;
                e=1;
                t=1;
            }
            else if(a[i]&&e==1)
            {
                p2=i;
                t=2;
            }
            if(a[i]==0&&t==1)
            {
                q[r++].from=p1;
                t=0;
                e=0;
            }
            else if(a[i]==0&&t==2)
            {
                q[r].from=p1;
                q[r++].to=p2;
                t=0;
                e=0;
            }

        }
        for(int i=0; i<r-1; i++)
        {
            if(q[i].to==0)
                printf("%d,",q[i].from);
            else
                printf("%d-%d,",q[i].from,q[i].to);
        }
        if(q[r-1].to==0)
            printf("%d\n",q[r-1].from);
        else
            printf("%d-%d\n",q[r-1].from,q[r-1].to);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int main()
{
    int a[100010];
    int b[100010];
    while(scanf("%d",&a[0])!=EOF)
    {
        getchar();
        int n = 1;
        while(scanf("%d",&a[n])!=EOF)
        {
            n++;
            getchar();
        }
        sort(a,a+n);
        a[n] = 9999999;
        int h = 0;
        for(int i=0;i<n;i++)
        {
            if(i == 0)
            {
                b[h++] = a[i];
            }
            else if(a[i]!=a[i-1])
            {
                b[h++] = a[i];
            }
        }
        b[h] = 99999;
        int p = b[0];
        int q = b[0];
        int flag = 0;
        int ff = 0;
        for(int i=1;i<=h;i++)
        {
            if(b[i] == b[i-1]+1)
            {
                p = b[i];
            }
            else if(b[i]!=b[i-1]+1)
            {
                ff = 1;
                if(flag == 1)
                {
                    printf(",");
                }
                flag = 1;
                if(p == q)
                {
                    printf("%d",p);
                }
                else
                {
                    printf("%d-%d",q,p);
                }
                p = b[i];
                q = b[i];
            }
        }
       printf("\n");

    }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct node
{
    int from,to;
} q[10000];
int main()
{
    int a[1010];
    char s[150];
    int p1,p2,e,t;
    while(gets(s)!=NULL)
    {
        memset(q,0,sizeof(q));
        int sum=0,k=0;
        e=0;
        t=0;
        memset(a,0,sizeof(a));
        int len=strlen(s);
        for(int i=0; i<len; i++)
        {
            if(s[i]>='0'&&s[i]<='9')
            {
                sum=sum*10+s[i]-'0';
            }
            else if(s[i]==',')
            {
                a[sum]=1;
                sum=0;
            }
        }
        a[sum]=1;
        int r=0;
        for(int i=1; i<=1009; i++)
        {
            if(a[i]&&e==0)
            {
                p1=i;
                e=1;
                t=1;
            }
            else if(a[i]&&e==1)
            {
                p2=i;
                t=2;
            }
            if(a[i]==0&&t==1)
            {
                q[r++].from=p1;
                t=0;
                e=0;
            }
            else if(a[i]==0&&t==2)
            {
                q[r].from=p1;
                q[r++].to=p2;
                t=0;
                e=0;
            }

        }
        for(int i=0; i<r-1; i++)
        {
            if(q[i].to==0)
                printf("%d,",q[i].from);
            else
                printf("%d-%d,",q[i].from,q[i].to);
        }
        if(q[r-1].to==0)
            printf("%d\n",q[r-1].from);
        else
            printf("%d-%d\n",q[r-1].from,q[r-1].to);
    }
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cctype>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define ll long long
#define maxn 116
#define pp pair<int,int>
#define INF 0x3f3f3f3f
#define max(x,y) ( ((x) > (y)) ? (x) : (y) )
#define min(x,y) ( ((x) > (y)) ? (y) : (x) )
using namespace std;
char str[10100];
int main()
{

	while(~scanf("%s",str)){
	set <int> s;int tem;char sb[6];
	for(int i=0;i<=strlen(str);i++)
	{
		if(str[i]==','||str[i]=='\0')
		{
			int p=0,q=i;
			while((--q)>=0&&str[q]!=',')sb[p++]=str[q];
			sb[p]='\0';strrev(sb);sscanf(sb,"%d",&tem);
			s.insert(tem);
		}
	}
	vector <int> a(s.begin(),s.end());
	int ansx[1010],ansy[1010],p=0;
	for(int i=0;i<a.size()-1;i++)
	{
		int pos=i;
		while(i+1<a.size()&&a[i]+1==a[i+1])
			i++;
		ansx[p]=a[pos];ansy[p++]=a[i];
	}
	if(ansy[p-1]!=a[a.size()-1])
	{
		ansx[p]=a[a.size()-1];
		ansy[p++]=a[a.size()-1];
	}
	for(int i=0;i<p;i++)
	{
		if(i!=p-1)
		{
			if(ansx[i]==ansy[i])
			printf("%d,",ansx[i]);
			else
			printf("%d-%d,",ansx[i],ansy[i]);
		}
		else
		{
			if(ansx[i]==ansy[i])
			printf("%d\n",ansx[i]);
			else
			printf("%d-%d\n",ansx[i],ansy[i]);
		}
	}
  }
	return 0;
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <stack>
using namespace std;
int n,a[1001],b[1001],t,tb,ff;
int main()
{
    while(scanf("%d",&a[0])!=EOF)
    {
        ff=0;
        t=1;
        tb=0;
        getchar();
        while(scanf("%d",&a[t])!=EOF)
        {
            getchar();
            t++;
        }
        sort(a,a+t);
        b[tb++]=a[0];
        for(int i=1; i<t; i++)
        {
            if(a[i]!=a[i-1])
                b[tb++]=a[i];
        }
        int l,r,j;
        /*for(int i=0; i<tb; i++)
        {
            printf("%d\n",b[i]);
        }*/
        for(int i=0; i<tb;)
        {
            l=i;
            r=i;
            for(j=i+1; j<tb;)
            {
                if(b[j]==b[j-1]+1)
                {
                    r=j;
                    j++;
                    if(j==tb)
                    {
                        if(r-l>0)
                        {
                            if(ff==0)
                            {
                                printf("%d-%d",b[l],b[r]);
                                ff=1;
                            }
                            else  printf(",%d-%d",b[l],b[r]);

                        }
                        else if(l==r)
                        {
                            if(ff==0)
                            {
                                printf("%d",b[l]);
                                ff=1;
                            }
                            else  printf(",%d",b[l]);
                        }
                    }
                }
                else
                {
                    if(r-l>0)
                    {
                        if(ff==0)
                        {
                            printf("%d-%d",b[l],b[r]);
                            ff=1;
                        }
                        else  printf(",%d-%d",b[l],b[r]);

                    }
                    else if(l==r)
                    {
                        if(ff==0)
                        {
                            printf("%d",b[l]);
                            ff=1;
                        }
                        else  printf(",%d",b[l]);
                    }
                    break;
                }
            }
            i=j;
        }
        if(b[tb-1]!=b[tb-2]+1)
        {
            if(ff==0)
            {
                ff=1;
                printf("%d",b[tb-1]);
            }
            else  printf(",%d",b[tb-1]);
        }
        if(t==1)
        printf("%d\n",a[0]);
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool arr[1500]={false};
int main()
{
    int n;

    while(scanf("%d,", &n) != EOF)
    {
      arr[n]=true;
    }
     int j,x=-1;
    for(int i = 1 ; i<=1000 ; i+=j)
    {
        if(arr[i])
        {
             j = i;
            while(arr[j]) j++;
            j--;
            if(x!=-1) cout<<",";
            else x = 1;
            cout<<i<<"-"<<j;

        }
    }

    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool arr[1500]={false};
int main()
{
    int n;

    while(scanf("%d,", &n) != EOF)
    {
      arr[n]=true;
    }
     int j,x=-1;
    for(int i = 1 ; i<=1000 ; i=j+1)
    {
        if(arr[i])
        {
             j = i;
            while(arr[j]) j++;
            j--;
            if(x!=-1) cout<<",";
            else x = 1;
            cout<<i<<"-"<<j;

        }
    }

    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
bool arr[1500]={false};
int main()
{
    int n;

    while(scanf("%d,", &n) != EOF)
    {
      arr[n]=true;
    }
     int j,x=-1;
    for(int i = 1 ; i<=1000 ; i=++j)
    {
        if(arr[i])
        {
             j = i;
            while(arr[j]) j++;
            j--;
            if(x!=-1) cout<<",";
            else x = 1;
            if(i==j) cout<<i;
            else
            cout<<i<<"-"<<j;

        }
    }

    return 0;
}


//Kapezov Zhandos
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <string>
#include <string.h>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <list>
#include <functional>
#include <bitset>
#include <numeric>
#include <iomanip>
#include <ctime>
#include <ctype.h>

using namespace std;
typedef long long ll;
const double eps = 1e-9;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define sz size()
#define sqr(x) ((x)*(x))
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define INF numeric_limits<int>::max()
//#define debug
#ifdef debug
        FILE * fp = fopen("debug.txt", "wt");
        #define dbg fp
#endif
int x, l, r;
bool u[2000], b=0;

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input","rt",stdin);
		freopen("output","wt",stdout);
	#endif
		memset(u, 0, sizeof(u));
		while (scanf("%d", &x) == 1) {
			scanf("%*c");
			u[x] = 1;
		}
		l = r = 0;
		for (int i = 1; i < 1001; i++)
		{
			if (u[i]) {
				if (l == 0) l = r = i; else
				r++;
			} else {
				if (l == 0 && r == 0) continue;
				if (l == r)  {
					if (b) putchar(',');
					printf("%d", l);
					b = 1;
				} else {
					if (b) putchar(',');
					printf("%d-%d", l, r);
					b = 1;
				}
				l = r = 0;
			}
		}
		if (l) {
			if (b)	putchar(',');
			printf("%d", l);
			if (l<r) printf("-%d", r);
		}
	return 0;
}


#include<iostream>
#include<math.h>
#include<vector>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<fstream>
#include<string>
#include<sstream>
#include<map>
using namespace std;
string s;
char ch;
int x,i,l,r,k;
bool a[10000];
int main()
{
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 memset(a,0,sizeof(a)); k=0;
  while (cin>>ch)
  {
   if (ch!=',') {s+=ch;continue;}
   stringstream(s)>>x;
   s.clear();
   a[x]=1;
  }
  stringstream(s)>>x;
  a[x]=1;
 l=-1; r=-1;

 for (i=1;i<1001;i++)
  if (a[i])
  {
   if (l==-1) l=i; else r=i;
  } else
  {
   if (l==r && l==-1) continue;
   k++;
   if (k>1) cout<<",";
   if (l==r || r==-1) cout<<l; else cout<<l<<"-"<<r;
   l=r=-1;
  }

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


//Kapezov Zhandos
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <string>
#include <string.h>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <list>
#include <functional>
#include <bitset>
#include <numeric>
#include <iomanip>
#include <ctime>
#include <ctype.h>

using namespace std;
typedef long long ll;
const double eps = 1e-9;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define sz size()
#define sqr(x) ((x)*(x))
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define INF numeric_limits<int>::max()
//#define debug
#ifdef debug
        FILE * fp = fopen("debug.txt", "wt");
        #define dbg fp
#endif
int x, l, r;
bool u[2000], b=0;

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input","rt",stdin);
		freopen("output","wt",stdout);
	#endif
		memset(u, 0, sizeof(u));
		while (scanf("%d", &x) == 1) {
			scanf("%*c");
			u[x] = 1;
		}
		l = r = 0;
		for (int i = 1; i < 1001; i++)
		{
			if (u[i]) {
				if (l == 0) l = r = i; else
				r++;
			} else {
				if (l == 0 && r == 0) continue;
				if (l == r)  {
					if (b) putchar(',');
					printf("%d", l);
					b = 1;
				} else {
					if (b) putchar(',');
					printf("%d-%d", l, r);
					b = 1;
				}
				l = r = 0;
			}
		}
	return 0;
}


#include<iostream>
#include<math.h>
#include<vector>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<fstream>
#include<string>
#include<string.h>
#include<sstream>
#include<map>
using namespace std;
string s;
char ch;
int x,i,l,r,k;
bool a[10000];
int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
 memset(a,0,sizeof(a)); k=0;
  while (cin>>ch)
  {
   if (ch!=',') {s+=ch;continue;}
   stringstream(s)>>x;
   s.clear();
   a[x]=1;
  }
  stringstream(s)>>x;
  a[x]=1;
 l=-1; r=-1;

 for (i=1;i<1001;i++)
  if (a[i])
  {
   if (l==-1) l=i; else r=i;
  } else
  {
   if (l==r && l==-1) continue;
   k++;
   if (k>1) cout<<",";
   if (l==r || r==-1) cout<<l; else cout<<l<<"-"<<r;
   l=r=-1;
  }

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


#include<iostream>
#include<string>
using namespace std;
int main(){
int k,b=-1;
bool a[1002];
string ch;
for(int i=0;i<1001;i++)
a[i]=false;
a[1001]=false;
int len;
cin>>ch;
if(ch=="1")
{
    cout<<1<<endl;
    return 0;
}
len=ch.length();
k=0;
for(int i=0;i<len;i++)
{
if(ch[i]!=',')
{
k=k*10+(int(ch[i])-48);
}
else
{
if(k>b)
b=k;
a[k]=true;
k=0;
}
}
a[k]=true;
int s=0;
int i;
for(i=0;i<=b;i++)
{
    if(a[i])
    {
       cout<<i;
       if(a[i+1])
       {
       cout<<"-";
       while(a[i])
       {
       i++;
       }
       cout<<i-1;
       if(i==b+1)
       break;
       cout<<",";
       }
       else
       {
       if(i<b)
       cout<<",";
       }
    }
}
cout<<endl;
cin>>i;
return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
cin>>n;
int k,b=-1;
bool a[1002];
string ch;
for(int i=0;i<1001;i++)
a[i]=false;
a[1001]=false;
int len;

cin>>ch;
len=ch.length();
k=0;
for(int i=0;i<len;i++)
{

if(ch[i]!=',')
{
k=k*10+(int(ch[i])-48);
if(k>b)
b=k;
a[k]=true;
}
else
k=0;
}

int s=0;
int i;
for(i=0;i<=b;i++)
{
    if(a[i])
    {
       cout<<i;
       if(a[i+1])
       {
       cout<<"-";
       while(a[i])
       {
       i++;
       }
       cout<<i-1;
       if(i==b+1)
       break;
       cout<<",";
       }
       else
       {
       if(i<b)
       cout<<",";
       }
    }
}
cout<<endl;
return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main(){
int k,b=-1;
bool a[1002];
string ch;
for(int i=0;i<1001;i++)
a[i]=false;
a[1001]=false;
int len;
cin>>ch;
len=ch.length();
k=0;
for(int i=0;i<len;i++)
{
if(ch[i]!=',')
{
k=k*10+(int(ch[i])-48);

}
else
{
if(k>b)
b=k;
a[k]=true;
k=0;
}
}

int s=0;
int i;
for(i=0;i<=b;i++)
{
    if(a[i])
    {
       cout<<i;
       if(a[i+1])
       {
       cout<<"-";
       while(a[i])
       {
       i++;
       }
       cout<<i-1;
       if(i==b+1)
       break;
       cout<<",";
       }
       else
       {
       if(i<b)
       cout<<",";
       }
    }
}
cout<<endl;
cin>>i;
return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main(){
int k,b=-1;
bool a[1002];
string ch;
for(int i=0;i<1001;i++)
a[i]=false;
a[1001]=false;
int len;
cin>>ch;
len=ch.length();
k=0;
for(int i=0;i<len;i++)
{
if(ch[i]!=',')
{
k=k*10+(int(ch[i])-48);
if(k>b)
b=k;
a[k]=true;
}
else
k=0;
}

int s=0;
int i;
for(i=0;i<=b;i++)
{
    if(a[i])
    {
       cout<<i;
       if(a[i+1])
       {
       cout<<"-";
       while(a[i])
       {
       i++;
       }
       cout<<i-1;
       if(i==b+1)
       break;
       cout<<",";
       }
       else
       {
       if(i<b)
       cout<<",";
       }
    }
}
cout<<endl;
cin>>i;
return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main(){
int k,b=-1;
bool a[1002];
string ch;
for(int i=0;i<1001;i++)
a[i]=false;
a[1001]=false;
int len;
cin>>ch;
len=ch.length();
k=0;
for(int i=0;i<len;i++)
{
if(ch[i]!=',')
{
k=k*10+(int(ch[i])-48);
}
else
{
if(k>b)
b=k;
a[k]=true;
k=0;
}
}
a[k]=true;
int s=0;
int i;
for(i=0;i<=b;i++)
{
    if(a[i])
    {
       cout<<i;
       if(a[i+1])
       {
       cout<<"-";
       while(a[i])
       {
       i++;
       }
       cout<<i-1;
       if(i==b+1)
       break;
       cout<<",";
       }
       else
       {
       if(i<b)
       cout<<",";
       }
    }
}
cout<<endl;
cin>>i;
return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main(){
int k,b=-1;
bool a[1002];
string ch;
for(int i=0;i<1001;i++)
a[i]=false;
a[1001]=false;
int len;
cin>>ch;
len=ch.length();
if(len==1)
{
cout<<ch<<endl;
return 0;
}
k=0;
for(int i=0;i<len;i++)
{
if(ch[i]!=',')
{
k=k*10+(int(ch[i])-48);
}
else
{
if(k>b)
b=k;
a[k]=true;
k=0;
}
}
a[k]=true;
int s=0;
int i;
for(i=0;i<=b;i++)
{
    if(a[i])
    {
       cout<<i;
       if(a[i+1])
       {
       cout<<"-";
       while(a[i])
       {
       i++;
       }
       cout<<i-1;
       if(i==b+1)
       break;
       cout<<",";
       }
       else
       {
       if(i<b)
       cout<<",";
       }
    }
}
cout<<endl;
cin>>i;
return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main(){
    int k,b=-1;
    bool a[1002];
    string ch;
    for(int i=0;i<1001;i++)
        a[i]=false;
    a[1001]=false;
    int len;
    cin>>ch;
    len=ch.length();
    if(len==1)
    {
        cout<<ch<<endl;
        return 0;
    }
    k=0;
    for(int i=0;i<len;i++)
    {
        if(ch[i]!=',')
        {
            k=k*10+(int(ch[i])-48);
        }
        else
        {
            if(k>b)
                b=k;
            a[k]=true;
            k=0;
        }
    }
    if(k>b)
        b=k;
    a[k]=true;
    k=0;
    int s=0;
    int i;
    for(i=0;i<=b;i++)
    {
        if(a[i])
        {
            cout<<i;
            if(a[i+1])
            {
                cout<<"-";
                while(a[i])
                {
                    i++;
                }
                cout<<i-1;
                if(i==b+1)
                    break;
                cout<<",";
            }
            else
            {
                if(i<b)
                    cout<<",";
            }
        }
    }
    cout<<endl;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int k,b=-1;
bool a[1002];
char ch;
for(int i=0;i<1001;i++)
a[i]=false;
a[1001]=false;
while(cin>>k)
{
if(k>b)
b=k;
a[k]=true;
cin>>ch;
}
int s=0;
int i;
for(i=0;i<=b;i++)
{
    if(a[i])
    {
       cout<<i;
       if(a[i+1])
       {
       cout<<"-";
       while(a[i])
       {
       i++;
       }
       cout<<i-1;
       if(i==b+1)
       break;
       cout<<",";
       }
       else
       {
       if(i<b)
       cout<<",";
       }
    }
}
cout<<endl;
cin>>n;
return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define MAX 1000

using namespace std;
char temp[MAX];
int n[MAX];
int i,j,k;

int main()
{
    //freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    string a;
    while(cin >> a)
    {

        for(i=0,j=0,k=0; i<a.size(); i++)
        {

            if(a[i]==',')
            {
                temp[j]='.';
                n[k++]=atoi(temp);
                j=0;
            }

            else{
                temp[j++]=a[i];
            }
        }

        temp[j]='.';
        n[k]=atoi(temp);

        sort(n,n+k+1);

        if(k==0){
            cout << n[0] << "\n";
            continue;
        }

        /*for(i=0; i<=k; i++)
            cout << n[i] << "  ";*/

        int trail=1;
        int st = 0;
        bool i_f=false;

        for(i=1; i<=k; i++)
        {
            if( (n[i-1]+1) == n[i])
                trail++;

            else if(n[i-1]==n[i])
                continue;

            else
            {
                if(trail>1)
                {
                    if(i_f==true)
                        cout << "," << n[st] << "-" << n[st]+trail-1;

                    else
                    {
                        cout << n[st] << "-" << n[st]+trail-1;
                        i_f=true;
                    }

                    trail=1;
                    st=i;
                }

                else
                {
                    if(i_f==false)
                    {
                        cout << n[st];
                        i_f=true;
                    }
                    else
                        cout << "," << n[st];

                    st=i;
                }
            }

        }

        if(trail>1)
        {
            cout << "," << n[st] << "-" << n[st]+trail-1;
        }

        else
            cout << "," << n[st];

        cout << "\n";

        a.clear();
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define MAX 1000

using namespace std;
char temp[MAX];
int n[MAX];
int i,j,k;

int main()
{
    freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    string a;
    while(cin >> a)
    {

        for(i=0,j=0,k=0; i<a.size(); i++)
        {

            if(a[i]==',')
            {
                temp[j]='.';
                n[k++]=atoi(temp);
                j=0;
            }

            else{
                temp[j++]=a[i];
            }
        }

        temp[j]='.';
        n[k]=atoi(temp);

        sort(n,n+k+1);

        bool v=false;

        for(i=1; i<=k; i++){
            if(n[i-1]!=n[i])
                v=true;
        }

        if(k==0 || v==false){
            cout << n[0] << "\n";
            continue;
        }

        int trail=1;
        int st = 0;
        bool i_f=false;

        for(i=1; i<=k; i++)
        {
            if( (n[i-1]+1) == n[i])
                trail++;

            else if(n[i-1]==n[i])
                continue;

            else
            {
                if(trail>1)
                {
                    if(i_f==true)
                        cout << "," << n[st] << "-" << n[st]+trail-1;

                    else
                    {
                        cout << n[st] << "-" << n[st]+trail-1;
                        i_f=true;
                    }

                    trail=1;
                    st=i;
                }

                else
                {
                    if(i_f==false)
                    {
                        cout << n[st];
                        i_f=true;
                    }
                    else
                        cout << "," << n[st];

                    st=i;
                }
            }

        }

        if(trail>1)
        {
            cout << "," << n[st] << "-" << n[st]+trail-1;
        }

        else
            cout << "," << n[st];

        cout << "\n";

        a.clear();
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define MAX 1000

using namespace std;
char temp[MAX];
int n[MAX];
int i,j,k;

int main()
{
    //freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    string a;
    while(cin >> a)
    {

        for(i=0,j=0,k=0; i<a.size(); i++)
        {

            if(a[i]==',')
            {
                temp[j]='.';
                n[k++]=atoi(temp);
                j=0;
            }

            else{
                temp[j++]=a[i];
            }
        }

        temp[j]='.';
        n[k]=atoi(temp);

        sort(n,n+k+1);

        bool v=false;

        for(i=1; i<=k; i++){
            if(n[i-1]!=n[i])
                v=true;
        }

        if(k==0 || v==false){
            cout << n[0] << "\n";
            continue;
        }

        int trail=1;
        int st = 0;
        bool i_f=false;

        for(i=1; i<=k; i++)
        {
            if( (n[i-1]+1) == n[i])
                trail++;

            else if(n[i-1]==n[i])
                continue;

            else
            {
                if(trail>1)
                {
                    if(i_f==true)
                        cout << "," << n[st] << "-" << n[st]+trail-1;

                    else
                    {
                        cout << n[st] << "-" << n[st]+trail-1;
                        i_f=true;
                    }

                    trail=1;
                    st=i;
                }

                else
                {
                    if(i_f==false)
                    {
                        cout << n[st];
                        i_f=true;
                    }
                    else
                        cout << "," << n[st];

                    st=i;
                }
            }

        }

        if(trail>1)
        {
            if(i_f==false)
            cout << n[st] << "-" << n[st]+trail-1;

            else
            cout << "," << n[st] << "-" << n[st]+trail-1;
        }

        else
            cout << "," << n[st];

        cout << "\n";

        a.clear();
    }
    return 0;
}


#include <iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{

    string in;
    while(getline(cin,in))
    {
         int i=0,j=0,ary[10000],count;
        for(i=0;i<=1000;i++)
        ary[i]=0;

        for(i=0;i<in.length();i++)
        {
            if(in[i]==',')
            {
                j++;
                continue;
            }
            else
            ary[j]=ary[j]*10+in[i]-48;
        }

       // for(i=0;i<=j;i++)
       // cout<<ary[i]<<endl;

        sort(ary,ary+j+1);
        ary[j+1]=ary[j]+10;

//        for(i=0;i<=j;i++)
//        cout<<ary[i]<<endl;

        count =0;
        for(i=0;i<=j;i++)
        {

            if((ary[i+1]-ary[i])==0 || (ary[i+1]-ary[i])==1 )
            {
                count++;
            }
            else
            {
                if(count>0 && i!=j && ary[i-count]<ary[i])
                cout<<ary[i-count]<<"-"<<ary[i]<<",";
                else if (count>0 && i==j && ary[i-count]<ary[i])
                cout<<ary[i-count]<<"-"<<ary[i]<<endl;
                else if (count>0 && i!=j && ary[i-count]==ary[i])
                cout<<ary[i]<<",";
                else if (count>0 && i==j && ary[i-count]==ary[i])
                cout<<ary[i]<<endl;
                else if (count==0 && i!=j)
                cout<<ary[i]<<",";
                else if (count==0 && i==j)
                cout<<ary[i]<<endl;

                count=0;
            }

//            for(k=i+1;k<=j;k++)
//            {
//                if((ary[k]-ary[i])==0 || (ary[k]-ary[i])==1 )
//                continue;
//            }
        }
        in.clear();

    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <sstream>
#include <map>
#include <string>
#include <queue>

using namespace std;

#define FOR(i, L, U) for(int i=(int)L; i<=(int)U; i++)
#define FORD(i, U, L) for(int i=(int)U; i>=(int)L; i--)

#define READ(x) freopen(x, "r", stdin)
#define WRITE(x) freopen(x, "w", stdout)

#define PB push_back
#define SZ size()

#define SQR(x) ((x)*(x))
#define INF 99999999

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector< vector<bool> > VVB;
typedef pair<int, int> II;
typedef map<int, int> MII;
typedef map<char, int> MCI;
typedef map<string, int> MSI;

#define WHITE 0
#define GRAY 1
#define BLACK 2

string line;
int get[1001];
VI v;

int main()
{
 //   READ("input.txt");
  //  WRITE("output.txt");

    int TC, tc;
    int temp;

    while(getline(cin, line)) {
        FOR(i, 0, line.SZ-1)
            if(line[i] == ',') line[i] = ' ';

        stringstream ss(line);

        memset(get, 0, sizeof(get));
        while(ss >> temp) {
            if(get[temp] == 0)
                v.PB(temp);
            get[temp] = 1;
        }

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

        bool one = false;
        int l, r;
        l = r = 0;
        FOR(i, 1, v.SZ-1) {
            if(v[i] - v[i-1] > 1) {
                if(one == true) cout << ",";
                if( r - l == 0)
                    cout << v[l];
                else cout << v[l] << "-" << v[r];
                one = true;
                l = r = i;

            }
            else if(v[i] - v[i-1] == 1)
                r++;
        }

        if(one == true) cout << ",";
        if( r - l == 0)
            cout << v[l];
        else cout << v[l] << "-" << v[r];

        cout<< "\n";

        v.clear();
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define MAX 1000

using namespace std;
char temp[MAX];
int n[MAX];
int i,j,k;

int main()
{
   // freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    string a;
    while(cin >> a)
    {

        for(i=0,j=0,k=0; i<a.size(); i++)
        {

            if(a[i]==',')
            {
                temp[j]='.';
                n[k++]=atoi(temp);
                j=0;
            }

            else{
                temp[j++]=a[i];
            }
        }

        temp[j]='.';
        n[k]=atoi(temp);

        sort(n,n+k+1);

        bool v=false;

        for(i=1; i<=k; i++){
            if(n[i-1]!=n[i])
                v=true;
        }

        if(k==0 || v==false){
            cout << n[0] << "\n";
            continue;
        }

        int trail=1;
        int st = 0;
        bool i_f=false;

        for(i=1; i<=k; i++)
        {
            if( (n[i-1]+1) == n[i])
                trail++;

            else if(n[i-1]==n[i])
                continue;

            else
            {
                if(trail>1)
                {
                    if(i_f==true)
                        cout << "," << n[st] << "-" << n[st]+trail-1;

                    else
                    {
                        cout << n[st] << "-" << n[st]+trail-1;
                        i_f=true;
                    }

                    trail=1;
                    st=i;
                }

                else
                {
                    if(i_f==false)
                    {
                        cout << n[st];
                        i_f=true;
                    }
                    else
                        cout << "," << n[st];

                    st=i;
                }
            }

        }

        if(trail>1)
        {
            cout << "," << n[st] << "-" << n[st]+trail-1;
        }

        else
            cout << "," << n[st];

        cout << "\n";

        a.clear();
    }
    return 0;
}


#include <bits/stdc++.h>

#define N 100005
#define ll long long
#define inf 100005

using namespace std;

int a[1001];

int main() {
    freopen("in", "r", stdin);
    int x;
    scanf("%d", &x);
    string sol = "";
    a[x] = 1;
    while (scanf(",%d", &x) != EOF) {
        a[x] = 1;
    }
    int fin, inicio;
    bool seg = false;
    bool prim = true;
    for (int i = 1; i <= 1000; i++) {
        if (a[i] == 1 && seg == false) {
            fin = i;
            inicio = i;
            seg = true;
        } else if (a[i] == 1 && seg == true) {
            fin++;
        } else if (a[i] == 0) {
            if (seg == true) {
                if (prim == true) {
                    if (inicio != fin) {
                        printf("%d-%d", inicio, fin);
                    } else {
                        printf("%d", inicio);
                    }
                    prim=false;
                } else {
                    if (inicio != fin) {
                        printf(",%d-%d", inicio, fin);
                    } else {
                        printf(",%d", inicio);
                    }
                }
            }
            seg = false;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define N 100005
#define ll long long
#define inf 100005

using namespace std;

int a[1001];

int main() {
//  freopen("in", "r", stdin);
    int x;
    scanf("%d", &x);
    string sol = "";
    a[x] = 1;
    while (scanf(",%d", &x) != EOF) {
        a[x] = 1;
    }
    int fin, inicio;
    bool seg = false;
    bool prim = true;
    for (int i = 1; i <= 1000; i++) {
        if (a[i] == 1 && seg == false) {
            fin = i;
            inicio = i;
            seg = true;
        } else if (a[i] == 1 && seg == true) {
            fin++;
        } else if (a[i] == 0) {
            if (seg == true) {
                if (prim == true) {
                    if (inicio != fin) {
                        printf("%d-%d", inicio, fin);
                    } else {
                        printf("%d", inicio);
                    }
                    prim=false;
                } else {
                    if (inicio != fin) {
                        printf(",%d-%d", inicio, fin);
                    } else {
                        printf(",%d", inicio);
                    }
                }
            }
            seg = false;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define N 100005
#define ll long long
#define inf 100005

using namespace std;

int a[1001];
int len;
char cad[100000];
int x=0;

int nextInt(int inicio){
    x=0;
    string num="";
    if(inicio>=len){
        return len;
    }

    int pos=inicio;
    while(pos<len){
        if(cad[pos]==','){
            x=atoi(num.c_str());
            return pos;
        }else{
            num+=cad[pos];
        }
        pos++;
    }
    x=atoi(num.c_str());
    return pos-1 ;
}

int main() {
//  freopen("in", "r", stdin);
    scanf("%s",cad);
    len=strlen(cad);
    int pos=0;
    while(pos<len){
        pos=nextInt(pos);
        pos++;
        a[x]=1;
    }
    int fin, inicio;
    bool seg = false;
    bool prim = true;
    for (int i = 1; i <= 1000; i++) {
        if (a[i] == 1 && seg == false) {
            fin = i;
            inicio = i;
            seg = true;
        } else if (a[i] == 1 && seg == true) {
            fin++;
        } else if (a[i] == 0) {
            if (seg == true) {
                if (prim == true) {
                    if (inicio != fin) {
                        printf("%d-%d", inicio, fin);
                    } else {
                        printf("%d", inicio);
                    }
                    prim=false;
                } else {
                    if (inicio != fin) {
                        printf(",%d-%d", inicio, fin);
                    } else {
                        printf(",%d", inicio);
                    }
                }
            }
            seg = false;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define N 100005
#define ll long long
#define inf 100005

using namespace std;

int a[1001];
int len;
char cad[100000];
int x=0;

int nextInt(int inicio){
    x=0;
    string num="";
    if(inicio>=len){
        return len;
    }

    int pos=inicio;
    while(pos<len){
        if(cad[pos]==','){
            x=atoi(num.c_str());
            return pos;
        }else{
            num+=cad[pos];
        }
        pos++;
    }
    x=atoi(num.c_str());
    return pos ;
}

int main() {
//  freopen("in", "r", stdin);
    scanf("%s",cad);
    len=strlen(cad);
    int pos=0;
    while(pos<len){
        pos=nextInt(pos);
        pos++;
        a[x]=1;
    }
    int fin, inicio;
    bool seg = false;
    bool prim = true;
    for (int i = 0; i <= 1001; i++) {
        if (a[i] == 1 && seg == false) {
            fin = i;
            inicio = i;
            seg = true;
        } else if (a[i] == 1 && seg == true) {
            fin++;
        } else if (a[i] == 0) {
            if (seg == true) {
                if (prim == true) {
                    if (inicio != fin) {
                        printf("%d-%d", inicio, fin);
                    } else {
                        printf("%d", inicio);
                    }
                    prim=false;
                } else {
                    if (inicio != fin) {
                        printf(",%d-%d", inicio, fin);
                    } else {
                        printf(",%d", inicio);
                    }
                }
            }
            seg = false;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

#define N 100005
#define ll long long
#define inf 100005

using namespace std;

int a[1001];
int len;
char cad[100000];
int x=0;

int nextInt(int inicio){
    x=0;
    string num="";
    if(inicio>=len){
        return len;
    }

    int pos=inicio;
    while(pos<len){
        if(cad[pos]==','){
            x=atoi(num.c_str());
            return pos;
        }else{
            num+=cad[pos];
        }
        pos++;
    }
    x=atoi(num.c_str());
    return pos-1 ;
}

int main() {
//  freopen("in", "r", stdin);
    scanf("%s",cad);
    len=strlen(cad);
    int pos=0;
    while(pos<len){
        pos=nextInt(pos);
        pos++;
        a[x]=1;
    }
    int fin, inicio;
    bool seg = false;
    bool prim = true;
    for (int i = 0; i <= 1000; i++) {
        if (a[i] == 1 && seg == false) {
            fin = i;
            inicio = i;
            seg = true;
        } else if (a[i] == 1 && seg == true) {
            fin++;
        } else if (a[i] == 0) {
            if (seg == true) {
                if (prim == true) {
                    if (inicio != fin) {
                        printf("%d-%d", inicio, fin);
                    } else {
                        printf("%d", inicio);
                    }
                    prim=false;
                } else {
                    if (inicio != fin) {
                        printf(",%d-%d", inicio, fin);
                    } else {
                        printf(",%d", inicio);
                    }
                }
            }
            seg = false;
        }
    }
    return 0;
}


//Begin: 13:30  Plan:15min
#include<cstdio>
#include<cstring>
using namespace std;
int n;
bool x[1005];
int main(){
	int xb,k,x2;
	int out1=-1,out2=-1;
	while(scanf("%d,",&k)==1){
		if(k==-1) break;
		x[k]=true;
	}
	for(xb=1;xb<=1001;xb++){
		if(!x[xb]){
			if(!x[xb-1]) continue;
			if(xb>1 && !x[xb-2]) {
			if(out2==-1 && out1!=-1) printf("%d,",out1);
			if(out2!=-1) printf("%d-%d,",out1,out2);
			out1=out2=-1;
				out1=xb-1,out2=-1;
				continue;
			}
			if(xb>1 && x[xb-2]){
			if(out2==-1 && out1!=-1) printf("%d,",out1);
			if(out2!=-1) printf("%d-%d,",out1,out2);
			out1=out2=-1;
				for(x2=xb-1;x2>=0;x2--) if(!x[x2]) break;
				out1=x2+1,out2=xb-1;
			}
		}
	}
	if(out2==-1 && out1!=-1) printf("%d",out1);
	if(out2!=-1) printf("%d-%d",out1,out2);
	out1=out2=-1;
	return 0;
}


//Begin: 13:30  Plan:15min
#include<cstdio>
#include<cstring>
using namespace std;
int n;
bool x[1005];
int main(){
	int xb,k,x2;
	int out1=-1,out2=-1;
	while(scanf("%d,",&k)==1){
		x[k]=true;
	}
	for(xb=1;xb<=1000;xb++){
		if(!x[xb]){
			if(!x[xb-1]) continue;
			if(xb>1 && !x[xb-2]) {
			if(out2==-1 && out1!=-1) printf("%d,",out1);
			if(out2!=-1) printf("%d-%d,",out1,out2);
			out1=out2=-1;
				out1=xb-1,out2=-1;
				continue;
			}
			if(xb>1 && x[xb-2]){
			if(out2==-1 && out1!=-1) printf("%d,",out1);
			if(out2!=-1) printf("%d-%d,",out1,out2);
			out1=out2=-1;
				for(x2=xb-1;x2>=0;x2--) if(!x[x2]) break;
				out1=x2+1,out2=xb-1;
			}
		}
	}
	if(out2==-1 && out1!=-1) printf("%d",out1);
	if(out2!=-1) printf("%d-%d",out1,out2);
	out1=out2=-1;
	return 0;
}


//Begin: 13:30  Plan:15min
#include<cstdio>
#include<cstring>
using namespace std;
int n;
bool x[1005];
int main(){
	int xb,k,x2;
	int out1=-1,out2=-1;
	while(scanf("%d,",&k)){
		if(k==-1) break;
		x[k]=true;
	}
	for(xb=1;xb<=1000;xb++){
		if(!x[xb]){
			if(!x[xb-1]) continue;
			if(xb>1 && !x[xb-2]) {
			if(out2==-1 && out1!=-1) printf("%d,",out1);
			if(out2!=-1) printf("%d-%d,",out1,out2);
			out1=out2=-1;
				out1=xb-1,out2=-1;
				continue;
			}
			if(xb>1 && x[xb-2]){
			if(out2==-1 && out1!=-1) printf("%d,",out1);
			if(out2!=-1) printf("%d-%d,",out1,out2);
			out1=out2=-1;
				for(x2=xb-1;x2>=0;x2--) if(!x[x2]) break;
				out1=x2+1,out2=xb-1;
			}
		}
	}
	if(out2==-1 && out1!=-1) printf("%d",out1);
	if(out2!=-1) printf("%d-%d",out1,out2);
	out1=out2=-1;
	return 0;
}


#include<cstdio>
using namespace std;
int sql[105],t,m,y;
char x[105];
int main(){
	scanf("%d %d",&t,&m);
	int xb,cnt=0,x2;
	for(xb=0;xb<t;xb++){
		scanf("%s",x);
		if(x[0]=='a'){
			scanf("%d",&y);
			int len=0;
			for(x2=0;x2<m && len<y;x2++) {
				if(sql[x2]==0)  len++; else len=0;
			}
			if(x2==m) printf("NULL\n");
			else {
				int e=x2-1;
				cnt++;
				for(x2=e-y+1;x2<=e;x2++) sql[x2]=cnt;
				printf("%d\n",cnt);
			}
		}
		else if(x[0]=='e'){
			scanf("%d",&y);
			bool fnd=0;
			for(x2=0;x2<m;x2++) if(sql[x2]==y) {
				sql[x2]=0;
				fnd=1;
			}
			if(!fnd) printf("ILLEGAL_ERASE_ARGUMENT\n");
		}
		else{
			int sp=0;
			while(sql[sp]>0) sp++;
			for(x2=sp+1;x2<m;x2++){
				if(sql[x2]>0){
					sql[sp]=sql[x2];
					sql[x2]=0;
					while(sql[sp]>0) sp++;
				}
			}
		}
	//	for(x2=0;x2<m;x2++) printf("%d ",sql[x2]);
	//	printf("\n");
	}
	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  set<int> app;
  string in;
  cin>>in;
  int pos=0;
  while(true){
    pos=in.find(",",pos);
    if(pos==string::npos)break;
    in[pos]=' ';
  }

  stringstream ss(in);
  int t;
  while(ss>>t)app.insert(t);

  int s=*app.begin();
  int zen=-1,last;

  FOR(siter,app){
    last=*siter;
    if(app.count(*siter+1))continue;
    if(app.count(*siter-1)){
      if(s==*siter){
    if(~zen)cout<<",";
    cout<<*siter;
    zen=*siter;
      }else{
    if(~zen)cout<<",";
    cout<<s<<"-"<<*siter;
    zen=*siter;
      }
    }else {
      if(~zen)cout<<",";
      cout<<*siter;
      s=*siter;
      zen=*siter;
    }
  }
  cout<<endl;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  set<int> app;
  string in;
  cin>>in;
  int pos=0;
  while(true){
    pos=in.find(",",pos);
    if(pos==string::npos)break;
    in[pos]=' ';
  }
 // cout<<in<<endl;

  stringstream ss(in);
  int t;
  while(ss>>t)app.insert(t);

  int s=*app.begin();
  int zen=-1,last;

  FOR(siter,app){
    last=*siter;
    if(app.count(*siter+1))continue;
    if(app.count(*siter-1)){
      if(s==*siter){
    if(~zen)cout<<",";
    cout<<*siter;
    zen=*siter;
      }else{
    if(~zen)cout<<",";
    cout<<s<<"-"<<*siter;
    zen=*siter;
      }
    }else s=*siter;
  }
  if(s==last){
    if(~zen)cout<<",";
    cout<<s;
  }else{
    if(~zen)cout<<",";
    cout<<s<<"-"<<last;
  }
  cout<<endl;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  set<int> app;
  string in;
  cin>>in;
  int pos=0;
  while(true){
    pos=in.find(",",pos);
    if(pos==string::npos)break;
    in[pos]=' ';
  }
  cout<<in<<endl;

  stringstream ss(in);
  int t;
  while(ss>>t)app.insert(t);

  int s=*app.begin();
  int zen=-1,last;

  FOR(siter,app){
    last=*siter;
    if(app.count(*siter+1))continue;
    if(app.count(*siter-1)){
      if(s==*siter){
	if(~zen)cout<<",";
	cout<<*siter;
	zen=*siter;
      }else{
	if(~zen)cout<<",";
	cout<<s<<"-"<<*siter;
	zen=*siter;
      }
    }else s=*siter;
  }
  if(s==last){
    if(~zen)cout<<",";
    cout<<s;
  }else{
    if(~zen)cout<<",";
    cout<<s<<"-"<<last;
  }
  cout<<endl;
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  set<int> app;
  string in;
  cin>>in;
  int pos=0;
  while(true){
    pos=in.find(",",pos);
    if(pos==string::npos)break;
    in[pos]=' ';
  }

  stringstream ss(in);
  int t;
  while(ss>>t)app.insert(t);

  int s=*app.begin();
  int zen=-1,last;

  FOR(siter,app){
    if(app.count(*siter+1)){
      if(app.count(*siter-1))continue;
      else s=*siter;
    }else if(app.count(*siter-1)){
      if(s==*siter){
    if(~zen)cout<<",";
    cout<<*siter;
    zen=*siter;
      }else{
    if(~zen)cout<<",";
    cout<<s<<"-"<<*siter;
    zen=*siter;
      }
    }else {
      if(~zen)cout<<",";
      cout<<*siter;
      s=*siter;
      zen=*siter;
    }
  }
  cout<<endl;
}


#include <bits/stdc++.h>

using namespace std;
ifstream fi ("pagenumber.inp");
ofstream fo ("pagenumber.out");
int a[1005]={0}, start=0;
string s,s1;

int doi(string x) {
    int c=1,ans=0;
    for (int i=x.size()-1; i>=0; i--) {
        ans+=c*(x[i]-48);
        c*=10;
    }
    return ans;
}

int main()
{
    getline(cin,s);
    int vt,x;
    while (!s.empty()) {
        vt=s.find(',');
        if (vt==-1) {
            vt=s.size();
            s1=s.substr(0,vt);
            s.erase(0,1);
        }
        else {
            s1=s.substr(0,vt);
            s.erase(0,vt+1);
        }
        x=doi(s1);
        a[x]++;
    }
    for (int i=0; i<=1001; i++) {
        if (a[i]!=0 && start==0) start=i;
        if (a[i]==0 && start!=0) {
            if (start==i-1) cout<<start;
            else cout<<start<<'-'<<i-1;
            vt=i;
            start=0;
            break;
        }
    }
    for (int i=vt; i<=1001; i++) {
        if (a[i] && start==0) start=i;
        if (a[i]==0)
            if (start!=0) {
                if (start!=i-1) cout<<','<<start<<'-'<<i-1;
                else cout<<','<<start;
                start=0;
            }
    }
    return 0;
}