    #include <iostream>                                                           
    #include <string>                                                             
    #include <sstream>                                                            
    #include <stdexcept>                                                          
                                                                                  
    int                                                                           
    main (int argc, char *argv[])                                                 
    {                                                                             
      std::string line;                                                           
                                                                                  
      while (std::getline (std::cin, line)) {                                     
        int N, M;                                                                 
        std::istringstream iss (line);                                            
                                                                                  
        if (!(iss >> N >> M))                                                     
          throw std::runtime_error ("input error #1");                            
                                                                                  
        std::cerr << "N = " << N << ", M = " << M << std::endl;                   
                                                                                  
        for (int i =0; i < M; ++i) {                                              
          std::string word;                                                       
          int value1, value2;                                                     
                                                                                  
          if (!(iss >> word))                                                     
            throw std::runtime_error ("input error #2");                          
                                                                                  
          std::istringstream inner_iss (word);                                    
                                                                                  
          if (inner_iss.peek () != '(' || !inner_iss.ignore () || !(inner_iss >> value1))
            throw std::runtime_error ("unexpected tokens; expected (, <value1>"); 
                                                                                  
          if (inner_iss.peek () != ',' || !inner_iss.ignore ()  || !(inner_iss >> value2))
            throw std::runtime_error ("unexpected tokens; expected , <value2>");  
                                                                                  
          if (inner_iss.peek () != ')')                                           
            throw std::runtime_error ("unexpected token expected )");             
                                                                                  
          std::cerr << "\t value1 = " << value1 << ", value2 = " << value2 << std::endl;
        }                                                                                                                                                                                                                 
      }                                                                           
    } 