import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
List<Scope> inScopeList = new ArrayList<Scope>();
//根据输入的数据获取所有区间
while (scanner.hasNext()) {
String str = scanner.next();
String[] strArr = str.split(",");
int x = Integer.parseInt(strArr[0]);
int y = Integer.parseInt(strArr[1]);
if (0 <= x && x <= y) {
inScopeList.add(new Scope(x, y));
}
}
//遍历区间集合,获取合并区间
List<Scope> outScopeList = new ArrayList<Scope>();
outScopeList.add(inScopeList.get(0));
for (int i=0; i+1 < inScopeList.size(); i++) {
//逐条合并
commonScopeList(outScopeList, inScopeList.get(i+1));
}
//给输出的合并区间排序
Map map = new HashMap();
List list = new ArrayList();
for (int i=0; i < outScopeList.size(); i++) {
Scope scope = outScopeList.get(i);
map.put(scope.x, scope);
list.add(scope.x);
}
Collections.sort(list);
//打印合并区间
String outStr = "";
for (int i=0; i < list.size(); i++) {
Scope scope = (Scope) map.get(list.get(i));
outStr = outStr + scope.x + "," + scope.y + " ";
}
System.out.println(outStr.trim());
}
public static void commonScopeList(List<Scope> outScopeList, Scope s) {
for (int i=0; i < outScopeList.size(); i++) {
Scope s1 = outScopeList.get(i);
//如果当前两个区间有交集,则重新初始化输入参数,再从头开始比较
if ((s1.x <= s.y && s1.y >= s.x) || (s.x <= s1.y && s.y >= s1.x)) {
outScopeList.remove(i);
i=-1;
s = new Scope(minInt(s1.x, s.x), maxInt(s1.y, s.y));
}
}
outScopeList.add(s);
}
public static int minInt(int x1, int x2) {
return x1 < x2 ? x1 : x2;
}
public static int maxInt(int y1, int y2) {
return y1 > y2 ? y1 : y2;
}
}
class Scope {
int x;
int y;
Scope(int x, int y) {
this.x = x;
this.y = y;
}
}