#include <testlib.h>

const int limit = 500;

int main() {
  registerValidation();
  int h = inf.readInt(1, limit, "h");
  inf.readSpace();
  int w = inf.readInt(1, limit, "w");
  inf.readEoln();
  bool was_E = false, was_X = false;
  for (int i = 0; i < h; i++) {
    std::string s = inf.readToken("[\\.#EX]+");
    ensuref((int)s.length() == w, "length of line #%d is %d, should be w=%d", i + 2, (int)s.length(), w);
    for (int j = 0; j < w; j++) {
      // fprintf(stderr, "bad character '%c' (#%d) in input\n", s[j] >= ' ' ? s[j] : '?', (int)s[j]);
      switch (s[j]) {
        case '.' :
        case '#' :
          break;
        case 'E' :
          ensuref(!was_E, "duplicate E");
          was_E = true;
          break;
        case 'X' :
          ensuref(!was_X, "duplicate X");
          was_X = true;
          break;
        default:
          ensuref(false, "bad character '%c' (#%d) in input", s[j] >= ' ' ? s[j] : '?', (int)s[j]);
      }
    }
    inf.readEoln();
  }
  inf.readEof();
  ensuref(was_E, "entry not found");
  ensuref(was_X, "exit not found");
  return 0;
}

