#include <cassert>
#include <complex>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <sstream>
#include <utility>

#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <memory.h>
//#include "bigint.h"

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define init(st) memset(st, 0, sizeof(st))
#define Pi 3.141592653589793

// String operations
template<class T>
void splitstr(const string &s, vector<T> &out) {
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

template<class T>
T read_value(string s) {
    T result;
    istringstream sin(s);
    sin >> result;
    return result;
}

#define read_int(s) read_value<int>(s)
#define read_ll(s) read_value<ll>(s)
#define read_float(s) read_value<float>(s)
#define read_double(s) read_value<double>(s)

string read_line() {
    string ret_val;
    getline(std::cin, ret_val);
    return ret_val;
}

template<class T>
void init_array(T *arr, int size, T value) {
    for (int i = 0; i < size; i++)
        arr[i] = value;
}

// Arithmetic operations
template<class T>
inline T gcd(T a, T b) {
    return (!a) ? b : gcd(b % a, a);
}

template<class T>
inline T mod(T a, T p) {
    a %= p;
    return (a < 0) ? a + p : a;
}

template<class T>
inline int numbits(T n) {
    return (!n) ? 0 : 1 + numbits(n & (n - 1));
}

template<class T>
inline T inverse(T a, T m) {
    a = mod<T>(a,m);
    return (a==1) ? 1 : mod((1-m*inverse(m%a,a))/a,m);
}

template<class T>
inline bool is_prime(T a) {
    T lim = (T)sqrt((double)a);
    for (T i = 2; i <= T(lim+1E-9); i++)
        if (a % i == 0)
           return false;
    return true;
}

template<class T>
inline T power(T a, T p, T mod) {
    if (!p) return 1;
    T temp = power(a, p>>1, mod);
    temp = (temp * temp) % mod;
    if (p&1)
        temp = (temp * a) % mod;
    return temp;
}

void get_primes(int start, int end, vector<int> &vi) {
    bool *p = new bool[end + 1];
    init_array<bool>(p, end+1, 0); p[1] = 1;
    for (int i = 2; i <= end; i++) {
        if (!p[i]) {
            if (i >= start)
                    vi.push_back(i);
            for (int j = 2*i; j <= end; j += i)
                    p[j] = 1;
        }
    }
    delete [] p;
}

// Graph operations
bool dfs(int current, int final, int total, vector<int> &visited, vector< vector<bool> > &edges, bool flow) {
    if (current == final) return true;
    if (visited[current]) return false;
    visited[current] = true;
    for (int i = 0; i < total; i++)
        if (edges[current][i] && dfs(i, final, total, visited, edges, flow)) {
            if (flow) {
                edges[current][i] = false;
                edges[i][current] = true;
            }
            return true;
        }
    return false;
}

int flow(int in, int out, int total, vector< vector<bool> > &edges) {
    int result = 0;
    for (vector<int> visited(total, 0); dfs(in, out, total, visited, edges, true); ++result)
        visited = vector<int>(total, 0);
    return result;
}

// Disjoint datasets
void create_set(int x, int *P, int *rank) {
    P[x] = x;
    rank[x] = 0;
}

int find_set(int x, int *P) {
    if (x != P[x]) P[x] = find_set(P[x], P);
    return P[x];
}

bool merge_sets(int x, int y, int *P, int *rank) {
    int Px = find_set(x, P);
    int Py = find_set(y, P);
    if(Px == Py) return false;
    if (rank[Px] > rank[Py]) P[Py] = Px;
    else P[Px] = Py;
    if (rank[Px] == rank[Py]) rank[Py]++;
    return true;
}

// Binary tree operations
template <typename T>
int read_cum_freq(int index, T *tree) {
    int sum = 0;
    while (index) {
        sum += tree[index];
        index -= (index & -index);
    }
    return sum;
}

template <typename T>
void upd_freq(int index, int mxIndex, int value, T *tree) {
    while (index <= mxIndex) {
        tree[index] += value;
        index += (index & -index);
    }
}

template <typename T>
int read_freq(int index, T *tree) {
    return read_cum_freq(index, tree) - read_cum_freq(index-1, tree);
}

// String algos.
void build_failure_function(const string &str, int *temp_arr) {
    temp_arr[0] = temp_arr[1] = 0;
    for (int i = 2; i <= sz(str); i++) {
        temp_arr[i] = -1;
        for (int ind = temp_arr[i-1]; temp_arr[i] == -1; ind = temp_arr[ind]) {
            if (str[ind] == str[i-1]) {
                temp_arr[i] = ind + 1;
            } else if (ind == 0) {
                temp_arr[i] = 0;
            }
        }
    }
}

void KMP(const string &text, const string &pattern, int *res) {
    int *temp_arr = new int[sz(pattern) + 1];
    build_failure_function(pattern, temp_arr);
    int i = 0;
    int ind = 0;
    while (i < sz(text)) {
        if (text[i] == pattern[ind]) {
            res[i] = ++ind;
            if (res[i] == sz(pattern)) {
                ind = temp_arr[ind];
            }
            i++;
        } else if (ind == 0) {
            res[i++] = 0;
        } else {
            ind = temp_arr[ind];
        }
    }
    delete [] temp_arr;
}

template <typename T, int N>
struct matrix {
    T m[N][N];
    T md;

    matrix(T md, bool unary = false) {
        this->md = md;
        init(m);
        if (unary) {
            for (int i = 0; i < N; i++) {
                m[i][i] = 1;
            }
        }
    }

    matrix operator*(const matrix &that) const {
        matrix ret_val(md, false);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N; k++) {
                    ret_val.m[i][j] += this->m[i][k] * that.m[k][j];
                    ret_val.m[i][j] %= md;
                }
            }
        }
        return ret_val;
    }

    vector<T> operator*(const vector<T> &vec) const {
        vector<T> ret_val(vec.size(), 0);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                ret_val[i] += m[i][j] * vec[j];
                ret_val[i] %= md;
            }
        }
        return ret_val;
    }

    matrix power(int pw) const {
        if (!pw) return matrix(md, true);
        if (pw == 1) return *this;
        matrix ret_val = power(pw>>1);
        ret_val = ret_val * ret_val;
        if (pw & 1) ret_val = ret_val * (*this);
        return ret_val;
    }
};

// Setup
void setup(int value, string name) {
    string name_in = name + ".in";
    string name_out = name + ".out";
    freopen(name_in.c_str(), "r", stdin);
    if (value) freopen(name_out.c_str(), "w", stdout);
}

int get_word(string &str) {
    reverse(str.begin(), str.end());
    if (str.find("soil") == 0) return 0;
    if (str.find("alail") == 0) return 1;
    if (str.find("rte") == 0) return 2;
    if (str.find("arte") == 0) return 3;
    if (str.find("sitini") == 0) return 4;
    if (str.find("setini") == 0) return 5;
    return -1;
}

int main() {
#ifdef LOCAL_HOST
    setup(0, "temp");
#endif
    vector<int> vi;
    string str;
    int mask = 0;
    while (std::cin >> str) {
        int group = get_word(str);
        if (group == -1) {
            std::cout << "NO" << std::endl; return 0;
        }
        mask |= (1 << (group & 1));
        vi.push_back(group / 2);
    }
    if (mask == 3) {
        std::cout << "NO" << std::endl; return 0;
    }
    if (vi.size() == 1) {
        std::cout << "YES" << std::endl; return 0;
    }
    if (count(vi.begin(), vi.end(), 1) != 1) {
        std::cout << "NO" << std::endl; return 0;
    }
    vi.erase(vi.begin(), unique(vi.begin(), vi.end()));
    if (count(vi.begin(), vi.end(), 0) > 1 ||
        count(vi.begin(), vi.end(), 2) > 1) {
            std::cout << "NO" << std::endl; return 0;
    }
    std::cout << "YES" << std::endl;
    return 0;
}


#include <cassert>
#include <complex>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <sstream>
#include <utility>

#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <memory.h>
//#include "bigint.h"

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define init(st) memset(st, 0, sizeof(st))
#define Pi 3.141592653589793

// String operations
template<class T>
void splitstr(const string &s, vector<T> &out) {
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

template<class T>
T read_value(string s) {
    T result;
    istringstream sin(s);
    sin >> result;
    return result;
}

#define read_int(s) read_value<int>(s)
#define read_ll(s) read_value<ll>(s)
#define read_float(s) read_value<float>(s)
#define read_double(s) read_value<double>(s)

string read_line() {
    string ret_val;
    getline(std::cin, ret_val);
    return ret_val;
}

template<class T>
void init_array(T *arr, int size, T value) {
    for (int i = 0; i < size; i++)
        arr[i] = value;
}

// Arithmetic operations
template<class T>
inline T gcd(T a, T b) {
    return (!a) ? b : gcd(b % a, a);
}

template<class T>
inline T mod(T a, T p) {
    a %= p;
    return (a < 0) ? a + p : a;
}

template<class T>
inline int numbits(T n) {
    return (!n) ? 0 : 1 + numbits(n & (n - 1));
}

template<class T>
inline T inverse(T a, T m) {
    a = mod<T>(a,m);
    return (a==1) ? 1 : mod((1-m*inverse(m%a,a))/a,m);
}

template<class T>
inline bool is_prime(T a) {
    T lim = (T)sqrt((double)a);
    for (T i = 2; i <= T(lim+1E-9); i++)
        if (a % i == 0)
           return false;
    return true;
}

template<class T>
inline T power(T a, T p, T mod) {
    if (!p) return 1;
    T temp = power(a, p>>1, mod);
    temp = (temp * temp) % mod;
    if (p&1)
        temp = (temp * a) % mod;
    return temp;
}

void get_primes(int start, int end, vector<int> &vi) {
    bool *p = new bool[end + 1];
    init_array<bool>(p, end+1, 0); p[1] = 1;
    for (int i = 2; i <= end; i++) {
        if (!p[i]) {
            if (i >= start)
                    vi.push_back(i);
            for (int j = 2*i; j <= end; j += i)
                    p[j] = 1;
        }
    }
    delete [] p;
}

// Graph operations
bool dfs(int current, int final, int total, vector<int> &visited, vector< vector<bool> > &edges, bool flow) {
    if (current == final) return true;
    if (visited[current]) return false;
    visited[current] = true;
    for (int i = 0; i < total; i++)
        if (edges[current][i] && dfs(i, final, total, visited, edges, flow)) {
            if (flow) {
                edges[current][i] = false;
                edges[i][current] = true;
            }
            return true;
        }
    return false;
}

int flow(int in, int out, int total, vector< vector<bool> > &edges) {
    int result = 0;
    for (vector<int> visited(total, 0); dfs(in, out, total, visited, edges, true); ++result)
        visited = vector<int>(total, 0);
    return result;
}

// Disjoint datasets
void create_set(int x, int *P, int *rank) {
    P[x] = x;
    rank[x] = 0;
}

int find_set(int x, int *P) {
    if (x != P[x]) P[x] = find_set(P[x], P);
    return P[x];
}

bool merge_sets(int x, int y, int *P, int *rank) {
    int Px = find_set(x, P);
    int Py = find_set(y, P);
    if(Px == Py) return false;
    if (rank[Px] > rank[Py]) P[Py] = Px;
    else P[Px] = Py;
    if (rank[Px] == rank[Py]) rank[Py]++;
    return true;
}

// Binary tree operations
template <typename T>
int read_cum_freq(int index, T *tree) {
    int sum = 0;
    while (index) {
        sum += tree[index];
        index -= (index & -index);
    }
    return sum;
}

template <typename T>
void upd_freq(int index, int mxIndex, int value, T *tree) {
    while (index <= mxIndex) {
        tree[index] += value;
        index += (index & -index);
    }
}

template <typename T>
int read_freq(int index, T *tree) {
    return read_cum_freq(index, tree) - read_cum_freq(index-1, tree);
}

// String algos.
void build_failure_function(const string &str, int *temp_arr) {
    temp_arr[0] = temp_arr[1] = 0;
    for (int i = 2; i <= sz(str); i++) {
        temp_arr[i] = -1;
        for (int ind = temp_arr[i-1]; temp_arr[i] == -1; ind = temp_arr[ind]) {
            if (str[ind] == str[i-1]) {
                temp_arr[i] = ind + 1;
            } else if (ind == 0) {
                temp_arr[i] = 0;
            }
        }
    }
}

void KMP(const string &text, const string &pattern, int *res) {
    int *temp_arr = new int[sz(pattern) + 1];
    build_failure_function(pattern, temp_arr);
    int i = 0;
    int ind = 0;
    while (i < sz(text)) {
        if (text[i] == pattern[ind]) {
            res[i] = ++ind;
            if (res[i] == sz(pattern)) {
                ind = temp_arr[ind];
            }
            i++;
        } else if (ind == 0) {
            res[i++] = 0;
        } else {
            ind = temp_arr[ind];
        }
    }
    delete [] temp_arr;
}

template <typename T, int N>
struct matrix {
    T m[N][N];
    T md;

    matrix(T md, bool unary = false) {
        this->md = md;
        init(m);
        if (unary) {
            for (int i = 0; i < N; i++) {
                m[i][i] = 1;
            }
        }
    }

    matrix operator*(const matrix &that) const {
        matrix ret_val(md, false);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N; k++) {
                    ret_val.m[i][j] += this->m[i][k] * that.m[k][j];
                    ret_val.m[i][j] %= md;
                }
            }
        }
        return ret_val;
    }

    vector<T> operator*(const vector<T> &vec) const {
        vector<T> ret_val(vec.size(), 0);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                ret_val[i] += m[i][j] * vec[j];
                ret_val[i] %= md;
            }
        }
        return ret_val;
    }

    matrix power(int pw) const {
        if (!pw) return matrix(md, true);
        if (pw == 1) return *this;
        matrix ret_val = power(pw>>1);
        ret_val = ret_val * ret_val;
        if (pw & 1) ret_val = ret_val * (*this);
        return ret_val;
    }
};

// Setup
void setup(int value, string name) {
    string name_in = name + ".in";
    string name_out = name + ".out";
    freopen(name_in.c_str(), "r", stdin);
    if (value) freopen(name_out.c_str(), "w", stdout);
}

int get_word(string &str) {
    reverse(str.begin(), str.end());
    if (str.find("soil") == 0) return 0;
    if (str.find("alail") == 0) return 1;
    if (str.find("rte") == 0) return 2;
    if (str.find("arte") == 0) return 3;
    if (str.find("sitini") == 0) return 4;
    if (str.find("setini") == 0) return 5;
    return -1;
}

int main() {
#ifdef LOCAL_HOST
    setup(0, "temp");
#endif
    vector<int> vi;
    string str;
    int mask = 0;
    while (std::cin >> str) {
        int group = get_word(str);
        if (group == -1) {
            std::cout << "NO" << std::endl; return 0;
        }
        mask |= (1 << (group & 1));
        vi.push_back(group / 2);
    }
    if (mask == 3) {
        std::cout << "NO" << std::endl; return 0;
    }
    if (vi.size() == 1) {
        std::cout << "YES" << std::endl; return 0;
    }
    if (count(vi.begin(), vi.end(), 1) != 1) {
        std::cout << "NO" << std::endl; return 0;
    }
    vi.erase(vi.begin(), unique(vi.begin(), vi.end()));
    if (count(vi.begin(), vi.end(), 0) > 1 ||
        count(vi.begin(), vi.end(), 2) > 1) {
            std::cout << "NO" << std::endl; return 0;
    }
    if (count(vi.begin(), vi.end(), 0) && vi[0] != 0) {
        std::cout << "NO" << std::endl; return 0;
    }
    if (count(vi.begin(), vi.end(), 2) && vi.back() != 2) {
        std::cout << "NO" << std::endl; return 0;
    }
    std::cout << "YES" << std::endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <sstream>
#include <set>
#include <map>
using namespace std;

#define N 100005

struct st {
    int r;
    int tp;
};

st s1, s2;

st a[N];
string s;

int end(string &a, string b) {
    if (a.size() < b.size()) {
        return 0;
    }
    return a.substr(a.size() - b.size()) == b;
}

int i, j, k, n, m, x, y, z, t, f;

int main() {
    while (cin >> s) {
        if (end(s, "lios")) {
            a[n].r = 0;
            a[n].tp = 0;
        } else if (end(s, "etr")) {
            a[n].r = 0;
            a[n].tp = 1;
        } else if (end(s, "initis")) {
            a[n].r = 0;
            a[n].tp = 2;
        } else if (end(s, "liala")) {
            a[n].r = 1;
            a[n].tp = 0;
        } else if (end(s, "etra")) {
            a[n].r = 1;
            a[n].tp = 1;
        } else if (end(s, "inites")) {
            a[n].r = 1;
            a[n].tp = 2;
        } else {
            cout << "NO" << endl;
            return 0;
        }
        n ++;
    }

    if (n == 1) {
        cout << "YES" << endl;
        return 0;
    }
    for (i = 1; i < n; i ++) {
        if (a[i].r != a[i-1].r) {
            cout << "NO" << endl;
            return 0;
        }
    }
    x = y = -1;
    for (i = 0; i < n; i ++) {
        if (a[i].tp == 1) {
            if (x == -1) {
                x = i;
            }
            y = i;
        }
    }
    f = 1;
    if (x == -1) {
        f = 0;
    }
    for (i = x - 1; i >= 0; i --) {
        if (a[i].tp != 0) {
            f = 0;
        }
    }
    for (i = y + 1; i < n; i ++) {
        if (a[i].tp != 2) {
            f = 0;
        }
    }
    for (i = x; i != y; i ++) {
        if (a[i].tp != 1) {
            f = 0;
        }
    }
    if (f == 1) {
        cout <<"YES" << endl;
        return 0;
    } else {
        cout << "NO" << endl;
        return 0;
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <sstream>
#include <set>
#include <map>
using namespace std;

#define N 100005

struct st {
    int r;
    int tp;
};

st s1, s2;

st a[N];
string s;

int end(string &a, string b) {
    if (a.size() < b.size()) {
        return 0;
    }
    return a.substr(a.size() - b.size()) == b;
}

int i, j, k, n, m, x, y, z, t, f;

int main() {
    while (cin >> s) {
        if (end(s, "lios")) {
            a[n].r = 0;
            a[n].tp = 0;
        } else if (end(s, "etr")) {
            a[n].r = 0;
            a[n].tp = 1;
        } else if (end(s, "initis")) {
            a[n].r = 0;
            a[n].tp = 2;
        } else if (end(s, "liala")) {
            a[n].r = 1;
            a[n].tp = 0;
        } else if (end(s, "etra")) {
            a[n].r = 1;
            a[n].tp = 1;
        } else if (end(s, "inites")) {
            a[n].r = 1;
            a[n].tp = 2;
        } else {
            cout << "NO" << endl;
            return 0;
        }
        n ++;
    }

    if (n == 1) {
        cout << "YES" << endl;
        return 0;
    }
    for (i = 1; i < n; i ++) {
        if (a[i].r != a[i-1].r) {
            cout << "NO" << endl;
            return 0;
        }
    }
    x = y = -1;
    for (i = 0; i < n; i ++) {
        if (a[i].tp == 1) {
            if (x == -1) {
                x = i;
            }
            y = i;
        }
    }
    f = 1;
    if (x == -1) {
        f = 0;
    }
    for (i = x - 1; i >= 0; i --) {
        if (a[i].tp != 0) {
            f = 0;
        }
    }
    for (i = y + 1; i < n; i ++) {
        if (a[i].tp != 2) {
            f = 0;
        }
    }
    if (f == 1) {
        cout <<"YES" << endl;
        return 0;
    } else {
        cout << "NO" << endl;
        return 0;
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <sstream>
#include <set>
#include <map>
using namespace std;

#define N 100005

struct st {
    int r;
    int tp;
};

st s1, s2;

st a[N];
string s;

int end(string &a, string b) {
    if (a.size() < b.size()) {
        return 0;
    }
    return a.substr(a.size() - b.size()) == b;
}

int i, j, k, n, m, x, y, z, t, f;

int main() {
    while (cin >> s) {
        if (end(s, "lios")) {
            a[n].r = 0;
            a[n].tp = 0;
        } else if (end(s, "etr")) {
            a[n].r = 0;
            a[n].tp = 1;
        } else if (end(s, "initis")) {
            a[n].r = 0;
            a[n].tp = 2;
        } else if (end(s, "liala")) {
            a[n].r = 1;
            a[n].tp = 0;
        } else if (end(s, "etra")) {
            a[n].r = 1;
            a[n].tp = 1;
        } else if (end(s, "inites")) {
            a[n].r = 1;
            a[n].tp = 2;
        } else {
            cout << "NO" << endl;
            return 0;
        }
        n ++;
    }

    if (n == 1) {
        cout << "YES" << endl;
        return 0;
    }
    for (i = 1; i < n; i ++) {
        if (a[i].r != a[i-1].r) {
            cout << "NO" << endl;
            return 0;
        }
    }
    x = y = -1;
    for (i = 0; i < n; i ++) {
        if (a[i].tp == 1) {
            if (x == -1) {
                x = i;
            }
            y = i;
        }
    }
    f = 1;
    if (x == -1) {
        f = 0;
    }
    for (i = x - 1; i >= 0; i --) {
        if (a[i].tp != 0) {
            f = 0;
        }
    }
    for (i = y + 1; i < n; i ++) {
        if (a[i].tp != 2) {
            f = 0;
        }
    }
    if (x != y) {
        f = 0;
    }
    if (f == 1) {
        cout <<"YES" << endl;
        return 0;
    } else {
        cout << "NO" << endl;
        return 0;
    }
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

pair<int, int> getInfo(string str) // part, sex
{
	if (str.size() >=4 && str.substr(str.size() - 4)=="lios" )
		return make_pair(0, 0);

	if (str.size() >=5 && str.substr(str.size() - 5)=="liala" )
		return make_pair(0, 1);

	if (str.size() >=3 && str.substr(str.size() - 3)=="etr" )
		return make_pair(1, 0);

	if (str.size() >=4 && str.substr(str.size() - 4)=="etra" )
		return make_pair(1, 1);

	if (str.size() >=6 && str.substr(str.size() - 6)=="initis" )
		return make_pair(2, 0);

	if (str.size() >=6 && str.substr(str.size() - 6)=="inites" )
		return make_pair(2, 1);

	return make_pair(-100, 0);
}

int main()
{
	ios::sync_with_stdio(false);

	string word;
	int prevPart = -1;
	bool res = true;
	bool man = false;
	bool woman = false;
	bool a=false,b=false,c=false ;
	int Count = 0;

	while(cin >> word)
	{
		pair<int, int> info = getInfo(word);
		if (info.first < prevPart)
			res = false;

		prevPart = info.first;

		if (info.second == 0)
			man = true;
		else
			woman = true;

		if (info.first == 0)
			a = true;

		if (info.first == 1)
			b = true;

		if (info.first == 2)
			c = true;

		Count++;
	}

	if (Count>1)
	{
		if (res==true && man!=woman && b==true)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	else if (Count==1)
	{
		if (res==true)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	else
		cout << "NO\n";

	return 0;
}


#include <iostream>
#include <string>

using namespace std;

pair<int, int> getInfo(string str) // part, sex
{
	if (str.size() >=4 && str.substr(str.size() - 4)=="lios" )
		return make_pair(0, 0);

	if (str.size() >=5 && str.substr(str.size() - 5)=="liala" )
		return make_pair(0, 1);

	if (str.size() >=3 && str.substr(str.size() - 3)=="etr" )
		return make_pair(1, 0);

	if (str.size() >=4 && str.substr(str.size() - 4)=="etra" )
		return make_pair(1, 1);

	if (str.size() >=6 && str.substr(str.size() - 6)=="initis" )
		return make_pair(2, 0);

	if (str.size() >=6 && str.substr(str.size() - 6)=="inites" )
		return make_pair(2, 1);

	return make_pair(-100, 0);
}

int main()
{
	ios::sync_with_stdio(false);

	string word;
	int prevPart = -1;
	bool res = true;
	bool man = false;
	bool woman = false;
	while(cin >> word)
	{
		pair<int, int> info = getInfo(word);
		if (info.first < prevPart)
			res = false;

		if (info.second == 0)
			man = true;
		else
			woman = true;
	}

	if (res==true && man!=woman)
		cout << "YES\n";
	else
		cout << "NO\n";

	return 0;
}


#include <iostream>
#include <string>

using namespace std;

pair<int, int> getInfo(string str) // part, sex
{
	if (str.size() >=4 && str.substr(str.size() - 4)=="lios" )
		return make_pair(0, 0);

	if (str.size() >=5 && str.substr(str.size() - 5)=="liala" )
		return make_pair(0, 1);

	if (str.size() >=3 && str.substr(str.size() - 3)=="etr" )
		return make_pair(1, 0);

	if (str.size() >=4 && str.substr(str.size() - 4)=="etra" )
		return make_pair(1, 1);

	if (str.size() >=6 && str.substr(str.size() - 6)=="initis" )
		return make_pair(2, 0);

	if (str.size() >=6 && str.substr(str.size() - 6)=="inites" )
		return make_pair(2, 1);

	return make_pair(-100, 0);
}

int main()
{
	ios::sync_with_stdio(false);

	string word;
	int prevPart = -1;
	bool res = true;
	bool man = false;
	bool woman = false;
	bool a=false,b=false,c=false ;
	int Count = 0;

	while(cin >> word)
	{
		pair<int, int> info = getInfo(word);
		if (info.first < prevPart)
			res = false;

		if (info.second == 0)
			man = true;
		else
			woman = true;

		if (info.first == 0)
			a = true;

		if (info.first == 1)
			b = true;

		if (info.first == 2)
			c = true;

		Count++;
	}

	if (Count>1)
	{
		if (res==true && man!=woman && b==true)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	else if (Count==1)
	{
		if (res==true)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	else
		cout << "NO\n";

	return 0;
}


#include <iostream>
#include <string>

using namespace std;

pair<int, int> getInfo(string str) // part, sex
{
	if (str.size() >=4 && str.substr(str.size() - 4)=="lios" )
		return make_pair(0, 0);

	if (str.size() >=5 && str.substr(str.size() - 5)=="liala" )
		return make_pair(0, 1);

	if (str.size() >=3 && str.substr(str.size() - 3)=="etr" )
		return make_pair(1, 0);

	if (str.size() >=4 && str.substr(str.size() - 4)=="etra" )
		return make_pair(1, 1);

	if (str.size() >=6 && str.substr(str.size() - 6)=="initis" )
		return make_pair(2, 0);

	if (str.size() >=6 && str.substr(str.size() - 6)=="inites" )
		return make_pair(2, 1);

	return make_pair(-100, 0);
}

int main()
{
	ios::sync_with_stdio(false);

	string word;
	int prevPart = -1;
	bool res = true;
	bool man = false;
	bool woman = false;
	int a=0,b=0,c=0 ;
	int Count = 0;

	while(cin >> word)
	{
		pair<int, int> info = getInfo(word);
		if (info.first < prevPart)
			res = false;
		else
			prevPart = info.first;

		if (info.second == 0)
			man = true;
		else
			woman = true;

		if (info.first == 0)
			a++;

		if (info.first == 1)
			b++;

		if (info.first == 2)
			c++;

		Count++;
	}

	if (Count>1)
	{
		if (res==true && man!=woman && b==1)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	else if (Count==1)
	{
		if (res==true)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	else
		cout << "NO\n";

	return 0;
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>
#include <utility>
#include <string>
#include <map>

using namespace std;

char word[100011];

string SUFF[] = {
    "lios",
    "liala",
    "etr",
    "etra",
    "initis",
    "inites",
};

void NO() {
    cout << "NO";
    exit(0);
}

int main() {
    //freopen("input.txt", "rt", stdin);

    int last = -1, count = 0;
    while (scanf("%s", word) > 0) {
        string w(word);
        int t = -1;
        for (int i = 0; i < 6; ++i) {
            if (w.length() >= SUFF[i].length())
                if (w.substr(w.length() - SUFF[i].length(), SUFF[i].length()) == SUFF[i]) {
                    t = i;
                    break;
                }
        }
        if (t == -1)
            NO();

        ++count;

        if (last == -1) {
            last = t;
            continue;
        }

        if (last % 2 != t % 2 || last/2 > t/2)
            NO();

        if (last/2 == 0 && t/2 == 2)
            NO();

        if (last/2 == 1 && t/2 != 2)
            NO();

        if (last/2 == 2 && count == 2)
            NO();

        last = t;
    }

    if (last == -1)
        exit(43);

    if (count > 1 && last/2 == 0)
        NO();

    cout << "YES";

    return 0;
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>
#include <utility>
#include <string>
#include <map>

using namespace std;

char word[100011];

string SUFF[] = {
    "lios",
    "liala",
    "etr",
    "etra",
    "initis",
    "inites",
};

void NO() {
    cout << "NO";
    exit(0);
}

int main() {
    //freopen("input.txt", "rt", stdin);

    int last = -1;
    while (scanf("%s", word) > 0) {
        string w(word);
        int t = -1;
        for (int i = 0; i < 6; ++i) {
            if (w.length() >= SUFF[i].length())
                if (w.substr(w.length() - SUFF[i].length()) == SUFF[i]) {
                    t = i;
                    break;
                }
        }
        if (t == -1)
            NO();

        if (last == -1) {
            last = t;
            continue;
        }

        if (last % 2 != t % 2)
            NO();

        if (last/2 == 0 && t/2 == 2)
            NO();

        if (last/2 == 1 && t/2 != 2)
            NO();

        last = t;
    }

    if (last == -1 || last/2 == 0)
        NO();

    cout << "YES";

    return 0;
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>
#include <utility>
#include <string>
#include <map>

using namespace std;

char word[100011];

string SUFF[] = {
    "lios",
    "liala",
    "etr",
    "etra",
    "initis",
    "inites",
};

void NO() {
    cout << "NO";
    exit(0);
}

int main() {
    //freopen("input.txt", "rt", stdin);

    int last = -1, count = 0;
    while (scanf("%s", word) > 0) {
        string w(word);
        int t = -1;
        for (int i = 0; i < 6; ++i) {
            if (w.length() >= SUFF[i].length())
                if (w.substr(w.length() - SUFF[i].length(), SUFF[i].length()) == SUFF[i]) {
                    t = i;
                    break;
                }
        }
        if (t == -1)
            NO();

        ++count;

        if (last == -1) {
            last = t;
            continue;
        }

        if (last % 2 != t % 2)
            NO();

        if (last/2 == 0 && t/2 == 2)
            NO();

        if (last/2 == 1 && t/2 != 2)
            NO();

        if (last/2 == 2 && count == 2)
            NO();

        last = t;
    }

    if (last == -1)
        exit(43);

    if (count > 1 && last/2 == 1)
        NO();

    cout << "YES";

    return 0;
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>
#include <utility>
#include <string>
#include <map>

using namespace std;

char word[100011];

string SUFF[] = {
    "lios",
    "liala",
    "etr",
    "etra",
    "initis",
    "inites",
};

void NO() {
    cout << "NO";
    exit(0);
}

int main() {
    //freopen("input.txt", "rt", stdin);

    int last = -1;
    while (scanf("%s", word) > 0) {
        string w(word);
        int t = -1;
        for (int i = 0; i < 6 && t != i; ++i) {
            if (w.length() >= SUFF[i].length())
                if (w.substr(w.length() - SUFF[i].length()) == SUFF[i]) {
                    t = i;
                    break;
                }
        }
        if (t == -1)
            NO();

        if (last == -1) {
            last = t;
            continue;
        }

        if (last % 2 != t % 2)
            NO();

        if (last/2 == 0 && t/2 == 2)
            NO();

        if (last/2 == 1 && t/2 != 2)
            NO();

        last = t;
    }

    cout << "YES";

    return 0;
}


#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>
#include <utility>
#include <string>
#include <map>

using namespace std;

char word[100011];

string SUFF[] = {
    "lios",
    "liala",
    "etr",
    "etra",
    "initis",
    "inites",
};

void NO() {
    cout << "NO";
    exit(0);
}

int main() {
    //freopen("input.txt", "rt", stdin);

    int last = -1, count = 0;
    while (scanf("%s", word) > 0) {
        string w(word);
        int t = -1;
        for (int i = 0; i < 6; ++i) {
            if (w.length() >= SUFF[i].length())
                if (w.substr(w.length() - SUFF[i].length()) == SUFF[i]) {
                    t = i;
                    break;
                }
        }
        if (t == -1)
            NO();

        ++count;

        if (last == -1) {
            last = t;
            continue;
        }

        if (last % 2 != t % 2)
            NO();

        if (last/2 == 0 && t/2 == 2)
            NO();

        if (last/2 == 1 && t/2 != 2)
            NO();

        last = t;
    }

    if (last == -1)
        exit(43);

    if (count > 1 && last/2 == 1)
        NO();

    cout << "YES";

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef vector< int > VI;
typedef vector< string > VS;
typedef pair< int, int > II;
typedef long long LL;
#define FOR(i,b,e) for(int (i)=(int)(b);(i)<(int)(e);++(i))
#define FORIT(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define INF 987654321

inline int isVerb(const string &a)
{
    int p = a.rfind("initis");
    if (p != string::npos && p+6 == (int)a.size()) return 1;
    int q = a.rfind("inites");
    //if (q == string::npos) return 0;
    if (q != string::npos && q+6 == (int)a.size()) return -1;
    return 0;
}

inline int isNoun(const string &a)
{
    int p = a.rfind("etr");
    if (p != string::npos && p+3 == (int)a.size()) return 1;
    int q = a.rfind("etra");
    //if (q == string::npos) return 0;
    if (q != string::npos && q+4 == (int)a.size()) return -1;
    return 0;
}

inline int isAdj(const string &a)
{
    int p = a.rfind("lios");
    if (p != string::npos && p+4 == (int)a.size()) return 1;
    int q = a.rfind("liala");
    //if (q == string::npos) return 0;
    if (q != string::npos && q+5 == (int)a.size()) return -1;
    return 0;
}

int main()
{
    VS seq;
    string buf;
    while (cin >> buf)
        seq.push_back(buf);
    int n = (int)seq.size();
    if (n == 1 && (isVerb(seq[0]) != 0 || isNoun(seq[0]) != 0 || isAdj(seq[0]) != 0) ) { cout << "YES" << endl; return 0; }
    if (n == 0) { cout << "NO" << endl; return 0; }
    int g;
    if ((g = isVerb(seq[0])) != 0) { cout << "NO" << endl; return 0; }
    if ((g = isNoun(seq[0])) != 0) {
        if (n == 1) { cout << "YES" << endl; return 0; }
        else if ((g = isVerb(seq[1])) == 0) { cout << "NO" << endl; return 0; }
        else if (isVerb(seq[1]) != 0) {
            g = isNoun(seq[0]);
            FOR(i, 1, n) {
                int g2 = isVerb(seq[i]);
                if (g != g2) { cout << "NO" << endl; return 0; }
            }
            cout << "YES" << endl; return 0;
        }
        cout << "NO" << endl;
    }
    if (isAdj(seq[0]) != 0) {
        g = isAdj(seq[0]);
        FOR(i, 1, n) {
            int g2 = isAdj(seq[i]);
            if (g2 == 0) {
                int g3 = isNoun(seq[i]);
                if (g3 != g) { cout << "NO" << endl; return 0; }
                FOR(j, i+1, n) {
                    int g4 = isVerb(seq[j]);
                    if (g != g4) { cout << "NO" << endl; return 0; }
                }
                cout << "YES" << endl; return 0;
            }
            else if (g2 != 0 && g2 != g) { cout << "NO" << endl; return 0; }
            else if (g2 != 0 && g2 == g) {}
        }
        cout << "NO" << endl; return 0;
    }
    cout << "NO" << endl;
    return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct st
{int p,r;};
st make(int p,int r)
{
	st z;
	z.p=p;
	z.r=r;
	return z;
}
string ss[6]={"lios","liala","etr","etra","initis","inites"};
vector <string> v;
vector <st> w;
int main()
{
	//ifstream in ("input.txt");
	string s;
	while(!cin.eof())
	{
		cin >> s;
		w.push_back(make(3,0));
		for (int i=0;i<6;i++)
			if (s.rfind(ss[i])!=s.npos&&s.rfind(ss[i])+ss[i].size()==s.size())
			{
				w[w.size()-1]=make(i/2,i%2);
				break;
			}
	}
	if (w.size()-1==1)
		if (w[0].p<3) cout << "YES" << endl;else cout << "NO" << endl;
	else
	{
		if (w[0].p==3)
		{
			cout << "NO" << endl;
			return 0;
		}
		else
		{
			int z=0;
			for (int i=1;i<w.size()-1;i++)
				if (w[i].p==3||w[i].p<w[i-1].p||w[i].r!=w[i-1].r)
				{
					cout << "NO" << endl;
					return 0;
				}
				else
					if (w[i].p==1) z++;
			if (z==1) cout << "YES" << endl;else cout << "NO" << endl;
		}
	}
	return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct st
{int p,r;};
st make(int p,int r)
{
	st z;
	z.p=p;
	z.r=r;
	return z;
}
string ss[6]={"lios","liala","etr","etra","initis","inites"};
vector <string> v;
vector <st> w;
int main()
{
	//ifstream in ("input.txt");
	string s;
	while(!cin.eof())
	{
		cin >> s;
		w.push_back(make(3,0));
		for (int i=0;i<6;i++)
			if (s.rfind(ss[i])!=s.npos&&s.rfind(ss[i])+ss[i].size()==s.size())
			{
				w[w.size()-1]=make(i/2,i%2);
				break;
			}
	}
	if (w.size()-1==1)
		if (w[0].p<3) cout << "YES" << endl;else cout << "NO" << endl;
	else
	{
		if (w[0].p==3)
		{
			cout << "NO" << endl;
			return 0;
		}
		else
		{
			for (int i=1;i<w.size()-1;i++)
				if (w[i].p==3||w[i].p<w[i-1].p||w[i].r!=w[i-1].r||w[i].p==1&&w[i-1].p==1)
				{
					cout << "NO" << endl;
					return 0;
				}
			cout << "YES" << endl;
		}
	}
	return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct st
{int p,r;};
st make(int p,int r)
{
	st z;
	z.p=p;
	z.r=r;
	return z;
}
string ss[6]={"lios","liala","etr","etra","initis","inites"};
vector <string> v;
vector <st> w;
int main()
{
	//ifstream in ("input.txt");
	string s;
	while(!cin.eof())
	{
		cin >> s;
		w.push_back(make(3,0));
		for (int i=0;i<6;i++)
			if (s.rfind(ss[i])!=s.npos&&s.rfind(ss[i])+ss[i].size()==s.size())
			{
				w[w.size()-1]=make(i/2,i%2);
				break;
			}
	}
	if (w.size()-1==1)
		if (w[0].p<3) cout << "YES" << endl;else cout << "NO" << endl;
	else
	{
		if (w[0].p==3)
		{
			cout << "NO" << endl;
			return 0;
		}
		else
		{
			int z=0;
			if (w[0].p==1) z++;
			for (int i=1;i<w.size()-1;i++)
				if (w[i].p==3||w[i].p<w[i-1].p||w[i].r!=w[i-1].r)
				{
					cout << "NO" << endl;
					return 0;
				}
				else
					if (w[i].p==1) z++;
			if (z==1) cout << "YES" << endl;else cout << "NO" << endl;
		}
	}
	return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct st
{int p,r;};
st make(int p,int r)
{
	st z;
	z.p=p;
	z.r=r;
	return z;
}
string ss[6]={"lios","liala","etr","etra","initis","inites"};
vector <string> v;
vector <st> w;
int main()
{
	ifstream in ("input.txt");
	string s;
	while(!in.eof())
	{
		in >> s;
		w.push_back(make(3,0));
		for (int i=0;i<6;i++)
			if (s.rfind(ss[i])!=s.npos&&s.rfind(ss[i])+ss[i].size()==s.size())
			{
				w[w.size()-1]=make(i/2,i%2);
				break;
			}
	}
	if (w.size()==1)
		if (w[0].p<3) cout << "YES" << endl;else cout << "NO" << endl;
	else
	{
		if (w[0].p==3)
		{
			cout << "NO" << endl;
			return 0;
		}
		else
		{
			for (int i=1;i<w.size();i++)
				if (w[i].p==3||w[i].p<w[i-1].p||w[i].r!=w[i-1].r||w[i].p==1&&w[i-1].p==1)
				{
					cout << "NO" << endl;
					return 0;
				}
			cout << "YES" << endl;
		}
	}
	return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct st
{int p,r;};
st make(int p,int r)
{
	st z;
	z.p=p;
	z.r=r;
	return z;
}
string ss[6]={"lios","liala","etr","etra","initis","inites"};
vector <string> v;
vector <st> w;
int main()
{
	//ifstream in ("input.txt");
	string s;
	while(!cin.eof())
	{
		cin >> s;
		w.push_back(make(3,0));
		for (int i=0;i<6;i++)
			if (s.rfind(ss[i])!=s.npos&&s.rfind(ss[i])+ss[i].size()==s.size())
			{
				w[w.size()-1]=make(i/2,i%2);
				break;
			}
	}
	if (w.size()==1)
		if (w[0].p<3) cout << "YES" << endl;else cout << "NO" << endl;
	else
	{
		if (w[0].p==3)
		{
			cout << "NO" << endl;
			return 0;
		}
		else
		{
			for (int i=1;i<w.size();i++)
				if (w[i].p==3||w[i].p<w[i-1].p||w[i].r!=w[i-1].r||w[i].p==1&&w[i-1].p==1)
				{
					cout << "NO" << endl;
					return 0;
				}
			cout << "YES" << endl;
		}
	}
	return 0;
}


										/* in the name of Allah */
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define int64 long long
#define P pair<int, int>

int gen[100010];
int tp[100010];

void calc(int idx, string s){
	int n = s.length();
	if(n >= 4 && s.substr(n - 4, 4) == "lios"){
		gen[idx] = 1;
		tp[idx] = 1;
	}
	else if(n >= 5 && s.substr(n - 5, 5) == "liala"){
		gen[idx] = 2;
		tp[idx] = 1;
	}
	else if(n >= 3 && s.substr(n - 3, 3) == "etr"){
		gen[idx] = 1;
		tp[idx] = 2;
	}
	else if(n >= 4 && s.substr(n - 4, 4) == "etra"){
		gen[idx] = 2;
		tp[idx] = 2;
	}
	else if(n >= 6 && s.substr(n - 6, 6) == "initis"){
		gen[idx] = 1;
		tp[idx] = 3;
	}
	else if(n >= 6 && s.substr(n - 6, 6) == "inites"){
		gen[idx] = 2;
		tp[idx] = 3;
	}
	else{
		gen[idx] = tp[idx] = -1;
	}
}

int main(){
	int n = 0;
	string s;
	while(cin >> s)
		calc(n++, s);
	if(n == 1)
		cout << (tp[0] != -1 ? "YES" : "NO") << endl;
	else{
		string res = "YES";
		int cnt = (tp[0] == 2 ? 1 : 0);
		for(int i = 1; i < n; i++){
			if(gen[i] == -1 || gen[i] != gen[i - 1] || tp[i] < tp[i - 1])
				res = "NO";
			if(tp[i] == 2)
				cnt++;
		}
		if(cnt != 1)
			res = "NO";
		cout << res << endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
using namespace std;

int adj(char *s)
{
	int p=strlen(s);
	if(p>=4&&strcmp(s+p-4,"lios")==0)return 1;
	if(p>=5&&strcmp(s+p-5,"liala")==0)return 2;
	return 0;
}
int noun(char *s)
{
	int p=strlen(s);
	if(p>=3&&strcmp(s+p-3,"etr")==0)return 1;
	if(p>=4&&strcmp(s+p-4,"etra")==0)return 2;
	return 0;
}
int verb(char *s)
{
	int p=strlen(s);
	if(p>=6&&strcmp(s+p-6,"initis")==0)return 1;
	if(p>=6&&strcmp(s+p-6,"inites")==0)return 2;
	return 0;
}

int main()
{
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	char *s=new char[100100],*l=new char[100100];
	cin.getline(s,100100);
	int len=0,leng=strlen(s),l1,p=0,a=0,b;
	while(len<leng)
	{
		l1=sscanf(s+len,"%s",l);
		if(l1)len+=strlen(l)+1;
//cout<<l<<endl;
		if(p==0)
		{
			b=adj(l);if(a==0)a=b;
			if(b!=0&&a!=b){cout<<"NO";return 0;}
			if(b==0)
			{
				b=noun(l);
				if(b==0||(a!=0&&a!=b)){cout<<"NO";return 0;}
				p=1;a=b;
			}
		}
		else if(p==1)
		{
			b=verb(l);
			if(b!=a||b==0){cout<<"NO";return 0;}
		}
		memset(l,0,strlen(l)+10);
	}
	if(p!=0)cout<<"YES";else cout<<"NO";
	return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
using namespace std;

int adj(char *s)
{
	int p=strlen(s);
	if(p>=4&&strcmp(s+p-4,"lios")==0)return 1;
	if(p>=5&&strcmp(s+p-5,"liala")==0)return 2;
	return 0;
}
int noun(char *s)
{
	int p=strlen(s);
	if(p>=3&&strcmp(s+p-3,"etr")==0)return 1;
	if(p>=4&&strcmp(s+p-4,"etra")==0)return 2;
	return 0;
}
int verb(char *s)
{
	int p=strlen(s);
	if(p>=6&&strcmp(s+p-6,"initis")==0)return 1;
	if(p>=6&&strcmp(s+p-6,"inites")==0)return 2;
	return 0;
}

int main()
{
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	char *s=new char[100100],*l=new char[100100];
	cin.getline(s,100100);
	int len=0,leng=strlen(s),l1,p=0,a=0,b;
	while(len<leng)
	{
		l1=sscanf(s+len,"%s ",l);
		if(l1)len+=strlen(l)+1;
//cout<<l<<endl;
		if(p==0)
		{
			b=adj(l);if(a==0)a=b;
			if(b!=0&&a!=b){cout<<"NO";return 0;}
			if(b==0)
			{
				b=noun(l);
				if(b==0||(a!=0&&a!=b)){cout<<"NO";return 0;}
				p=1;a=b;
			}
		}
		else if(p==1)
		{
			b=verb(l);
			if(b!=a||b==0){cout<<"NO";return 0;}
		}
		memset(l,0,strlen(l)+10);
	}
	if(a!=0)cout<<"YES";
	else cout<<"NO";
	return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
using namespace std;

int adj(char *s)
{
	int p=strlen(s);
	if(p>=4&&strcmp(s+p-4,"lios")==0)return 1;
	if(p>=5&&strcmp(s+p-5,"liala")==0)return 2;
	return 0;
}
int noun(char *s)
{
	int p=strlen(s);
	if(p>=3&&strcmp(s+p-3,"etr")==0)return 1;
	if(p>=4&&strcmp(s+p-4,"etra")==0)return 2;
	return 0;
}
int verb(char *s)
{
	int p=strlen(s);
	if(p>=6&&strcmp(s+p-6,"initis")==0)return 1;
	if(p>=6&&strcmp(s+p-6,"inites")==0)return 2;
	return 0;
}

int main()
{
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	char *s=new char[100100],*l=new char[100100];
	cin.getline(s,100100);
	int len=0,leng=strlen(s),l1,p=0,a=0,b,h=0;
	while(len<leng)
	{
		l1=sscanf(s+len,"%s ",l);
		if(l1)len+=strlen(l)+1;
		if(h==-1){cout<<"NO";return 0;}
//cout<<l<<endl;
		if(p==0)
		{
			b=adj(l);if(a==0)a=b;
			if(b!=0&&a!=b){cout<<"NO";return 0;}
			if(b==0)
			{
				b=noun(l);
				if(b==0&&h==0){b=verb(l);h=-1;}
				if(b==0||(a!=0&&a!=b)){cout<<"NO";return 0;}
				p=1;a=b;
			}else ++h;
		}
		else if(p==1)
		{
			b=verb(l);
			if(b!=a||b==0){cout<<"NO";return 0;}
		}
		memset(l,0,strlen(l)+10);
	}
	if(p==1||(a!=0&&h==1))cout<<"YES";
	else cout<<"NO";
	return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
using namespace std;

int adj(char *s)
{
	int p=strlen(s);
	if(p>=4&&strcmp(s+p-4,"lios")==0)return 1;
	if(p>=5&&strcmp(s+p-5,"liala")==0)return 2;
	return 0;
}
int noun(char *s)
{
	int p=strlen(s);
	if(p>=3&&strcmp(s+p-3,"etr")==0)return 1;
	if(p>=4&&strcmp(s+p-4,"etra")==0)return 2;
	return 0;
}
int verb(char *s)
{
	int p=strlen(s);
	if(p>=6&&strcmp(s+p-6,"initis")==0)return 1;
	if(p>=6&&strcmp(s+p-6,"inites")==0)return 2;
	return 0;
}

int main()
{
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	char *s=new char[100100],*l=new char[100100];
	cin.getline(s,100100);
	int len=0,leng=strlen(s),l1,p=0,a=0,b;
	while(len<leng)
	{
		l1=sscanf(s+len,"%s ",l);
		if(l1)len+=strlen(l)+1;
//cout<<l<<endl;
		if(p==0)
		{
			b=adj(l);if(a==0)a=b;
			if(b!=0&&a!=b){cout<<"NO";return 0;}
			if(b==0)
			{
				b=noun(l);
				if(b==0||(a!=0&&a!=b)){cout<<"NO";return 0;}
				p=1;a=b;
			}
		}
		else if(p==1)
		{
			b=verb(l);
			if(b!=a){cout<<"NO";return 0;}
		}
		memset(l,0,strlen(l)+10);
	}
	cout<<"YES";
	return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
using namespace std;

int adj(char *s)
{
	int p=strlen(s);
	if(p>=4&&strcmp(s+p-4,"lios")==0)return 1;
	if(p>=5&&strcmp(s+p-5,"liala")==0)return 2;
	return 0;
}
int noun(char *s)
{
	int p=strlen(s);
	if(p>=3&&strcmp(s+p-3,"etr")==0)return 1;
	if(p>=4&&strcmp(s+p-4,"etra")==0)return 2;
	return 0;
}
int verb(char *s)
{
	int p=strlen(s);
	if(p>=6&&strcmp(s+p-6,"initis")==0)return 1;
	if(p>=6&&strcmp(s+p-6,"inites")==0)return 2;
	return 0;
}

int main()
{
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	char *s=new char[100100],*l=new char[100100];
	cin.getline(s,100100);
	int len=0,leng=strlen(s),l1,p=0,a=0,b;
	while(len<leng)
	{
		l1=sscanf(s+len,"%s ",l);
		if(l1)len+=strlen(l)+1;
//cout<<l<<endl;
		if(p==0)
		{
			b=adj(l);if(a==0)a=b;
			if(b!=0&&a!=b){cout<<"NO";return 0;}
			if(b==0)
			{
				b=noun(l);
				if(b==0||(a!=0&&a!=b)){cout<<"NO";return 0;}
				p=1;a=b;
			}
		}
		else if(p==1)
		{
			b=verb(l);
			if(b!=a||b==0){cout<<"NO";return 0;}
		}
		memset(l,0,strlen(l)+10);
	}
	cout<<"YES";
	return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
using namespace std;

int adj(char *s)
{
	int p=strlen(s);
	if(p>=4&&strcmp(s+p-4,"lios")==0)return 1;
	if(p>=5&&strcmp(s+p-5,"liala")==0)return 2;
	return 0;
}
int noun(char *s)
{
	int p=strlen(s);
	if(p>=3&&strcmp(s+p-3,"etr")==0)return 1;
	if(p>=4&&strcmp(s+p-4,"etra")==0)return 2;
	return 0;
}
int verb(char *s)
{
	int p=strlen(s);
	if(p>=6&&strcmp(s+p-6,"initis")==0)return 1;
	if(p>=6&&strcmp(s+p-6,"inites")==0)return 2;
	return 0;
}

int main()
{
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	char *s=new char[100100],*l=new char[100100];
	cin.getline(s,100100);
	int len=0,leng=strlen(s),l1,p=0,a=0,b;
	while(len<leng)
	{
		l1=sscanf(s+len,"%s ",l);
		if(l1)len+=strlen(l)+1;
//cout<<l<<endl;
		if(p==0)
		{
			b=adj(l);if(a==0)a=b;
			if(b!=0&&a!=b){cout<<"NO";return 0;}
			if(b==0)
			{
				b=noun(l);
				if(b==0||(a!=0&&a!=b)){cout<<"NO";return 0;}
				p=1;a=b;
			}
		}
		else if(p==1)
		{
			b=verb(l);
			if(b!=a||b==0){cout<<"NO";return 0;}
		}
		memset(l,0,strlen(l)+10);
	}
	//if(p!=0)
		cout<<"YES";
	//else cout<<"NO";
	return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
using namespace std;

int adj(char *s)
{
	int p=strlen(s);
	if(p>=4&&strcmp(s+p-4,"lios")==0)return 1;
	if(p>=5&&strcmp(s+p-5,"liala")==0)return 2;
	return 0;
}
int noun(char *s)
{
	int p=strlen(s);
	if(p>=3&&strcmp(s+p-3,"etr")==0)return 1;
	if(p>=4&&strcmp(s+p-4,"etra")==0)return 2;
	return 0;
}
int verb(char *s)
{
	int p=strlen(s);
	if(p>=6&&strcmp(s+p-6,"initis")==0)return 1;
	if(p>=6&&strcmp(s+p-6,"inites")==0)return 2;
	return 0;
}

int main()
{
	ifstream cin("input.txt");
	ofstream cout("output.txt");
	char *s=new char[100100],*l=new char[100100];
	cin.getline(s,100100);
	int len=0,leng=strlen(s),l1,p=0,a=0,b;
	while(len<leng)
	{
		l1=sscanf(s+len,"%s",l);
		if(l1)len+=strlen(l)+1;
//cout<<l<<endl;
		if(p==0)
		{
			b=adj(l);if(a==0)a=b;
			if(b!=0&&a!=b){cout<<"NO";return 0;}
			if(b==0)
			{
				b=noun(l);
				if(b==0||(a!=0&&a!=b)){cout<<"NO";return 0;}
				p=1;a=b;
			}
		}
		else if(p==1)
		{
			b=verb(l);
			if(b!=a||b==0){cout<<"NO";return 0;}
		}
		memset(l,0,strlen(l)+10);
	}
	if(p!=0)cout<<"YES";else cout<<"NO";
	return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
using namespace std;

int adj(char *s)
{
	int p=strlen(s);
	if(p>=4&&strcmp(s+p-4,"lios")==0)return 1;
	if(p>=5&&strcmp(s+p-5,"liala")==0)return 2;
	return 0;
}
int noun(char *s)
{
	int p=strlen(s);
	if(p>=3&&strcmp(s+p-3,"etr")==0)return 1;
	if(p>=4&&strcmp(s+p-4,"etra")==0)return 2;
	return 0;
}
int verb(char *s)
{
	int p=strlen(s);
	if(p>=6&&strcmp(s+p-6,"initis")==0)return 1;
	if(p>=6&&strcmp(s+p-6,"inites")==0)return 2;
	return 0;
}

int main()
{
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	char *s=new char[100100],*l=new char[100100];
	cin.getline(s,100100);
	int len=0,leng=strlen(s),l1,p=0,a=0,b;
	while(len<leng)
	{
		l1=sscanf(s+len,"%s ",l);
		if(l1)len+=strlen(l)+1;
//cout<<l<<endl;
		if(p==0)
		{
			b=adj(l);if(a==0)a=b;
			if(b!=0&&a!=b){cout<<"NO";return 0;}
			if(b==0)
			{
				b=noun(l);
				if(b==0||(a!=0&&a!=b)){cout<<"NO";return 0;}
				p=1;a=b;
			}
		}
		else if(p==1)
		{
			b=verb(l);
			if(b!=a||b==0){cout<<"NO";return 0;}
		}
		memset(l,0,strlen(l)+10);
	}
	if(p!=0)cout<<"YES";else cout<<"NO";
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;

/*
-lios, а женского — на -liala.
-etr, а женского — на -etra.
-initis, а женского — на -inites.
*/
    char s[100005];
char    w[100005];

int main()
{
    int sex = -1, pos = 0, idx, len;
    bool sush = 0;
    int cntw = 0;
    len = 0, idx = 0;
    gets(w);
    len = strlen(w);
    while(1)
    {
        if(idx >= len)
            break;
        sscanf(w + idx, "%s", s);
        int sx, ps;
        int n = strlen(s);
        if(s[n - 4] == 'l' && s[n - 3] == 'i' && s[n - 2] == 'o' && s[n - 1] == 's')
        {
            sx = 1;
            ps = 1;
        }
        else if(s[n - 5] == 'l' && s[n - 4] == 'i' && s[n - 3] == 'a' && s[n - 2] == 'l' && s[n - 1] == 'a')
        {
            sx = 2;
            ps = 1;
        }
        else if(s[n - 3] == 'e' && s[n - 2] == 't' && s[n - 1] == 'r')
        {
            sx = 1;
            ps = 2;
        }
        else if(s[n -4] == 'e' && s[n - 3] == 't' && s[n - 2] == 'r' && s[n - 1] == 'a')
        {
            sx = 2;
            ps = 2;
        }
        else if(s[n - 6] == 'i' && s[n - 5] == 'n' && s[n - 4] == 'i' && s[n - 3] == 't' && s[n - 2] == 'i' && s[n - 1] == 's')
        {
            sx = 1;
            ps = 3;
        }
        else if(s[n - 6] == 'i' && s[n - 5] == 'n' && s[n - 4] == 'i' && s[n - 3] == 't' && s[n - 2] == 'e' && s[n - 1] == 's')
        {
            sx = 2;
            ps = 3;
        }
        else
        {
            printf("NO\n");
            return 0;
        }

        if(sex == -1 )
        {
            sex = sx;
            pos = ps;
        }
        else
        {
            if(sx != sex || pos > ps || (ps == 2 && pos == 2))
            {
                printf("NO\n");
                return 0;
            }
            pos = ps;
        }
            if(ps == 2)
                sush = 1;
            idx += n + 1;
            cntw++;
    }

    if(!sush && cntw > 1)
        printf("NO\n");
    else
        printf("YES\n");

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;

/*
-lios, а женского — на -liala.
-etr, а женского — на -etra.
-initis, а женского — на -inites.
*/
    char s[100005];
char    w[100005];

int main()
{
    int sex = -1, pos = 0, idx, len;
    bool sush = 0;
    len = 0, idx = 0;
    gets(w);
    len = strlen(w);
    while(1)
    {
        if(idx >= len)
            break;
        sscanf(w + idx, "%s", s);
        int sx, ps;
        int n = strlen(s);
        if(s[n - 4] == 'l' && s[n - 3] == 'i' && s[n - 2] == 'o' && s[n - 1] == 's')
        {
            sx = 1;
            ps = 1;
        }
        else if(s[n - 5] == 'l' && s[n - 4] == 'i' && s[n - 3] == 'a' && s[n - 2] == 'l' && s[n - 1] == 'a')
        {
            sx = 2;
            ps = 1;
        }
        else if(s[n - 3] == 'e' && s[n - 2] == 't' && s[n - 1] == 'r')
        {
            sx = 1;
            ps = 2;
        }
        else if(s[n -4] == 'e' && s[n - 3] == 't' && s[n - 2] == 'r' && s[n - 1] == 'a')
        {
            sx = 2;
            ps = 2;
        }
        else if(s[n - 6] == 'i' && s[n - 5] == 'n' && s[n - 4] == 'i' && s[n - 3] == 't' && s[n - 2] == 'i' && s[n - 1] == 's')
        {
            sx = 1;
            ps = 3;
        }
        else if(s[n - 6] == 'i' && s[n - 5] == 'n' && s[n - 4] == 'i' && s[n - 3] == 't' && s[n - 2] == 'e' && s[n - 1] == 's')
        {
            sx = 2;
            ps = 3;
        }
        else
        {
            printf("NO\n");
            return 0;
        }

        if(sex == -1 )
        {
            sex = sx;
            pos = ps;
        }
        else
        {
            if(sx != sex || pos > ps || (ps == 2 && pos == 2))
            {
                printf("NO\n");
                return 0;
            }
            pos = ps;
        }
            if(ps == 2)
                sush = 1;
            idx += n + 1;
    }

    if(!sush)
        printf("NO\n");
    else
        printf("YES\n");

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<algorithm>
using namespace std;

#define MAX 100007

char S[][77] = { "lios","liala","etr","etra","initis","inites"};

char Str[MAX+7];
char Tmp[MAX+7];

bool IsEnd( char *s1,char *s2 )
{
	long L1 = strlen( s1 );
	long L2 = strlen( s2 );
	long i=L1-1,j=L2-1;
	for( ;i>=0 && j>=0;i--,j-- ){
		if( s1[i]!=s2[j]) return false;
	}
	if( j<0 ) return true;
	return false;
}

bool IsBoy( char *p )
{
	long i;
	for( i=0;i<6;i+=2 ){
		if( IsEnd( p,S[i])) return true;
	}
	return false;
}

long GetType( char *p )
{
	long i;
	for( i=0;i<6;i++){
		if( IsEnd( p,S[i] )) break;
	}
	if( i<2 ) return 1;
	if( i<4 ) return 2;
	if( i<6 ) return 3;
	return -1;
}

int main( void )
{
	long i;

	//freopen("text1.txt","r",stdin );

	gets(Str);
	strcpy( Tmp,Str );//puts(Tmp);
	char *p = strtok( Tmp," " );
	bool Boy = false,Girl = false;
	while( p ){
		if( GetType(p)==-1 ){
			printf("NO\n");
			return 0;
		}//puts(p );
		bool b = IsBoy( p );
		if( b ) Boy = true;
		else Girl = true;
		p = strtok( NULL," ");
	}
	if( Boy == Girl ){
		printf("NO\n");
		return 0;
	}

	p = strtok( Str," " );
	while( p ){
		long T = GetType( p );//printf("a %ld\n",T );
		if( T>1 ) break;
		if( T!=1 ){
			printf("NO\n");
			return 0;
		}
		p = strtok( NULL," ");
	}

	while( p ){
		long T = GetType( p );//printf("b %ld\n",T);
		if( T>2 ) break;
		if( T!=2 ){
			printf("NO\n");
			return 0;
		}
		p = strtok( NULL," ");
	}

	while( p ){
		long T = GetType( p );//printf("c %ld\n",T );
		if( T!=3 ){
			printf("NO\n");
			return 0;
		}
		p = strtok( NULL," ");
	}
	printf("YES\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(int)n;(i)++)
int M;
vector<pair<pair<int,int>,int> > v;
bool alloc(int x,int id)
{
	int i,j;
	rep(i,M-x+1)
	{
			bool bad=false;
			rep(j,v.size())
			{
				int a=v[j].first.first,b=v[j].first.second;
				if(a<i+x && b>i)bad=true;
			}
		if(!bad)
		{
			v.push_back(make_pair(make_pair(i,i+x),id));
			cout<<id<<endl;
			return true;
		}
	}
	cout<<"NULL"<<endl;
	return false;
}
bool erase2(int id)
{
	int i;
	rep(i,v.size())
		if(v[i].second==id)
		{
			v.erase(v.begin()+i);
			return true;
		}
	return false;
}
void defragment(void)
{
	int i,sum=0;
	sort(v.begin(),v.end());
	rep(i,v.size())
	{
		int x=v[i].first.second-v[i].first.first;
		v[i].first.first=sum;
		v[i].first.second=sum+x;
		sum+=x;
	}
}
int main()
{
	int Q,x,i,id=1;
	cin>>Q>>M;
	rep(i,Q)
	{
		string s;
		cin>>s;
		if(s=="alloc")
		{
			cin>>x;
			if(alloc(x,id))id++;
		}else
		if(s=="erase")
		{
			cin>>x;
			if(!erase2(x))cout<<"ILLEGAL+ERASE_ARGUMENT"<<endl;
		}else
		{
			defragment();
		}
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string commed;//命令
    int time,m;//次数..内存大小

    scanf("%d%d",&time,&m);

    int line[m+1];
    memset(line,0,sizeof(line));//初始化内存
    int p1=1;//内存编号指针

    for(int i=1;i<=time;i++)
    {
        cin>>commed;//输入命令
        if(commed=="alloc")
        {
            int size;
            cin>>size;//输入连续内存大小
            bool f1=false;//一开始没有申请过空间
            int sum=0;//连续'空'计数和
            int begin=1,end=0;
            for(int i=1;i<=m;i++)
            {
                if(line[i]==0)//内存为'空'
                {
                    sum++;//连续'空'内存计数+1
                    end=i;//end为此'空'内存位置
                    if(sum==size)
                    {
//						cout<<"begin="<<begin<<" "<<"end="<<end<<endl;
                        for(int j=begin;j<=end;j++)
                        {
                            line[j]=p1;//从begin到end的'空'内存编号为内存编号(p1)
                        }
//						for(int a=1;a<=m;a++)
//						{
//							cout<<line[a]<<" ";
//						}
//						cout<<"p1="<<p1<<endl;//输出申请的空间的编号
                        cout<<p1<<endl;
                        p1++;//内存编号+1;
                        f1=true;//已申请过空间
                    }
                }
                else//遇见'实'内存
                {
                    sum=0;//不连续，计数清零
                    begin=i+1;//begin为'实'内存后一个
                }
                if(f1==true)//空间已经申请过
                {
                    break;
                }
                else//空间未申请过
                {
                    if(i==m)//已经搜索结束
                    {
                        cout<<"NULL\n";
                    }
                }
            }
        }
        if(commed=="erase")
        {
            int p2;
            cin>>p2;//内存块编号
            bool f2=false;//未释放
            for(int i=1;i<=m;i++)//搜索
            {
                if(line[i]==p2)//找到编号内存
                {
                    line[i]=0;//清零
                    f2=true;//已释放
                }
            }
//			for(int a=1;a<=m;a++)
//			{
//				cout<<line[a]<<" ";
//			}
//			cout<<"\n";
            if(f2==false||p2==0)
            {
                cout<<"ILLEGAL_ERASE_ARGUMENT\n";
            }
        }
        if(commed=="defragment")
        {
            int copy[101]={0};//空内存位置数组
            int p3=1;
            for(int i=1;i<=m;i++)
            {
                if(line[i]!=0)
                {
                    copy[p3]=line[i];
                    p3++;
                }
            }
            for(int i=1;i<=m;i++)
            {
                line[i]=copy[i];
            }
//			for(int a=1;a<=m;a++)
//			{
//				cout<<line[a]<<" ";
//			}
//			cout<<"\n";
        }
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#define gpt(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int n,m,u[100005],r=1;
bool cmp(int a,int b){
    if(a==0&&b==0){
        return 1;
    }
    else if(a!=0&&b==0){
        return 1;
    }
    else if(a==0&&b!=0){
        return 0;
    }
    else return 0;
}
int main(){
    cin>>n>>m;
    gpt(i,0,n){
        string str;
        cin>>str;
   //     gpt(j,0,m)cout<<u[j]<<' ';cout<<'\n';
        if(str=="alloc"){           //添加
            int k,e=0,o=0;
            cin>>k;
            bool bol=0;
            gpt(j,0,m){
                if(u[j]==0)o++;
                else{
                    o=0;
                    e=j+1;
                }
                if(o==k){
                    bol=1;
                    break;
                }
            }
            if(bol){
                gpt(q,e,e+k)u[q]=r;
                cout<<r<<'\n';
                r++;
            }
            if(!bol)cout<<"NULL\n";
        }
        if(str=="erase"){           //清除
            int k;
            cin>>k;
            if(k>=r||k<0){
                cout<<"ILLEGAL_ERASE_ARGUMENT\n";
                continue;
            }
            bool bol=0;
            gpt(j,0,m){
                if(u[j]==k){
                    bol=1;
                    int q=j;
                    while(u[q]==k){
                        u[q]=0;
                        q++;
                    }
                    break;
                }
            }
            if(!bol)cout<<"ILLEGAL_ERASE_ARGUMENT\n";
        }
        if(str=="defragment")sort(u,u+m,cmp);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int bytes[200],t,m,timer=1;
queue <int> q1;
void defragment(){
	for(int i=1;i<=m;i++){
		if(bytes[i]!=-1){
			q1.push(bytes[i]);
		}
	}
	int len=q1.size();
	memset(bytes,-1,sizeof(bytes));
	for(int i=1;i<=len;i++){
		bytes[i]=q1.front();
		q1.pop();
	}
}

void alloc(){
	int x;
	cin>>x;
	for(int i=1;i<=m;i++){
		if(i+x-1>m) break;
		else if(bytes[i]==-1){
			bool empty=true;
			for(int j=i;j<i+x;j++)
				if(bytes[j]!=-1) empty=false;
			if(empty==true){
				for(int j=i;j<i+x;j++)
					bytes[j]=timer;
				cout<<timer<<endl;
				timer++;
				return ;
			}else{ i=i+x-1; continue; }
		}
	}
	cout<<"NULL"<<endl;
}

void erase(){
	bool noexsit=true;
	int x;
	cin>>x;
	for(int i=1;i<=m;i++){
		if(bytes[i]==x){
			bytes[i]=-1;
			noexsit=false;
		}
	}
	if(noexsit==true) cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
}

int main(){
	memset(bytes,-1,sizeof(bytes));
	cin>>t>>m;
	for(int i=1;i<=t;i++){
		string opera;
		cin>>opera;
		if(opera=="alloc") alloc();
		else if(opera=="erase") erase();
		else if(opera=="defragment") defragment();
		/*for(int i=1;i<=m;i++)
			cout<<bytes[i]<<" ";
		cout<<endl;*/
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct memory
{
	int ind=0,len=0;
}f[1000];
int t,m;
int main()
{
	string s;
	int i,j,k,num=0,x,p,q;
	bool flag;
	cin>>t>>m;

	for(i=1;i<=t;i++)
	{
		cin>>s;
		if(s[0]=='a')//alloc申请空间
		{

			cin>>x;
			flag=false;
			p=1;
			while(p<m)
			{
				q=p;
				while(f[q].ind==0&&q<=m) q++;
				if(q-p>=x)
				{
					f[p].ind=++num;
					f[p].len=x;
					flag=true;
					break;
				}
				if(q<=m&&f[q].len>0)
					p=q+f[q].len;
				else
					p=q;
			}
			if(flag==true)
				cout<<num<<endl;
			else
				cout<<"NULL"<<endl;
		}
		else if(s[0]=='e')//erase删除空间
		{
			cin>>x;
			flag=false;
			for(j=1;j<=m;j++)
				if(f[j].ind==x)
				{
					f[j].ind=0;
					f[j].len=0;
					flag=true;
					break;
				}
			if(!flag)
				cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		}
		else//归并空间
		{
			memory f1[1000];
			k=1;
			for(j=1;j<=m;j++)
				if(f[j].ind!=0)
				{
					f1[k].ind=f[j].ind;
					f1[k].len=f[j].len;
					k=k+f[j].len;
				}
			memcpy(f,f1,sizeof(f));
		}

	}
	return 0;
}


#include<ios>
#include<iostream>
using namespace std;
const int MAXN=100+3;
int t,m;
int d[MAXN];
int ans;
int main(){
	ios_base::sync_with_stdio(false);
	cin>>t>>m;
	for(int o=1;o<=t;o++){
		string s;
		cin>>s;
		if(s=="alloc"){
			int n;
			cin>>n;
			int i,j=-1;
			for(i=0;i<m;i++){
				if(i-j==n&&!d[i]){
					break;
				}
				else if(d[i]){
					j=i;
				}
			}
			if(i-j==n&&i<m){
				cout<<++ans<<"\n";
				for(int k=j+1;k<=i;k++){
					d[k]=ans;
				}
			}
			else{
				cout<<"NULL"<<"\n";
			}
		}
		if(s=="erase"){
			int x;
			cin>>x;
			bool flag=0;
			for(int i=0;i<m;i++){
				if(d[i]==x&&x!=0){//x!=0***
					flag=1;
					d[i]=0;
				}
			}
			if(!flag){
				cout<<"ILLEGAL_ERASE_ARGUMENT"<<"\n";
			}
		}
		if(s=="defragment"){
			for(int i=0,j=0;i<m;i++){
				if(d[i]){
					swap(d[i],d[j]);
					j++;
				}
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int me[105]={0};
int n,m;
int x;
string s;
int cnt=0;
void alloc()
{
	bool flag=false;
	for(int i=1;i<=m;i++)
	{
		if(me[i]==0&&!flag)
		{
			for(int j=i;j<=i+x-1&&j<=m;j++)
				if(me[j]!=0)
				{
					break;
				}
				else if(me[j]==0&&j==i+x-1)
				{
					flag=true;
				}
			if(flag)
			{
				cnt++;
				for(int j=i;j<=i+x-1;j++)
				{
					me[j]=cnt;
				}
				cout<<cnt<<endl;
			}
		}
	}
	if(flag==false)
		cout<<"NULL"<<endl;
}
void erase()
{
	bool flag=false;
	for(int i=1;i<=m;i++)
	{
		if(me[i]==x)
		{
			me[i]=0;
			flag=true;
		}
	}
	if(!flag)
	cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
}
void defragment()
{
	for(int i=m-1;i>=1;i--)
	{
		for(int j=i;j>=1;j--)
		{
			if(me[j]==0)
			{
				int tmp=me[j+1];
				me[j]=tmp;
				me[j+1]=0;
			}
		}
	}
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		if(s[0]=='a')
		{
			cin>>x;
			alloc();
		}
		if(s[0]=='e')
		{
			cin>>x;
			erase();
		}
		if(s[0]=='d')
			defragment();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int d[101],t,m,c,b,i,j,k,l;string s;
int main(){
	cin>>t>>m;
	for(k=0;k<t;k++){
		cin>>s;
		if(s[0]=='a'){
			cin>>c;
			for(i=0,j=-1;i<m;i++)if(i-j==c&&!d[i])break;else if(d[i])j=i;
			if(i-j==c&&i<m){
				cout<<++b<<endl;
				for(l=j+1;l<=i;l++)d[l]=b;
			}
			else cout<<"NULL"<<endl;
		}
		else if(s[0]=='e'){
			cin>>c;
			for(i=0,j=0;i<m;i++) if(d[i]==c&&c!=0) d[i]=0,j=1;
			if(!j)cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		}
		else if(s[0]=='d')
			for(i=0,j=0;i<m;i++)if(d[i])l=d[j],d[j]=d[i],d[i]=l,j++;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <array>

int main()
{
    std::array<int, 100> Arr{ 0 };
    int t, m;
    std::cin >> t >> m;

    int id = 1; // 标记着最远的编号，从1开始
    std::string Command;
    while (t--)
    {
        std::cin >> Command;
        if (Command[0] == 'a')  // "alloc"
        {
            int p;
            std::cin >> p;

            int cnt = 0, idx = 0;
            bool OK = false;
            for (int i = 0; i < m; ++i)
            {
                if (!Arr[i])
                {
                    ++cnt;  // 去找有多少个连续的0
                }
                else
                {
                    cnt = 0;    // 中断了就清零重来
                    idx = i + 1;
                }

                if (cnt == p)   // 依题意，找到了第一个能存放p个单位的就立马跳出
                {
                    OK = true;
                    break;
                }
            }

            if (OK)
            {   // 从idx开始涂连续的p个
                for (int i = idx; i < idx + p; ++i)
                {
                    Arr[i] = id;
                }

                // 这里要加一了
                std::cout << id++ << std::endl;
            }
            else
            {
                std::puts("NULL");
            }
        }
        else if (Command[0] == 'e') // "erase"
        {
            int p;
            std::cin >> p;

            if (p > id || p <= 0)   // 删除最大标号以外的或者删除1以下的均为非法
            {
                std::puts("ILLEGAL_ERASE_ARGUMENT");
            }
            else
            {
                int f = false;
                int i;
                for (i = 0; i < m; ++i)
                {
                    if (Arr[i] == p)    // 去找要被删去的第一个数的下标
                    {
                        break;
                    }
                }

                while (Arr[i] == p)
                {
                    Arr[i] = 0; // 清零即是删除
                    ++i;
                    f = true;   // 标记删除操作被执行了
                }

                if (!f) // 如果这一次删除没有做任何操作，那么这个删除也是无效的
                {
                    std::puts("ILLEGAL_ERASE_ARGUMENT");
                }
            }
        }
        else   // "defragment"
        {
            int idx = 0;
            for (int i = 0; i < m; ++i)
            {
                if (Arr[i]) // 如果非零，则存放在前面
                {
                    Arr[idx++] = Arr[i];
                }
            }
            for (int i = idx; i < m; ++i)   // 后面那部分都是零
            {
                Arr[i] = 0;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,m;
vector < pair < pair < int , int > , int > > v;
bool alloc(int x,int id)
{
	int i,j;
	for (i=0;i<m-x+1;i++)
	{
		bool bad=false;
		for (j=0;j<v.size();j++)
		{
			int a=v[j].first.first;
			int b=v[j].first.second;
			if (a<i+x&&b>i) bad=true;
		}
		if (!bad)
		{
			v.push_back(make_pair(make_pair(i,i+x),id));
			cout<<id<<endl;
			return true;
		}
	}
	cout<<"NULL"<<endl;
	return false;
}
bool clean(int id)
{
	int i;
	for (i=0;i<v.size();i++)
		if (v[i].second==id)
		{
			v.erase(v.begin()+i);
			return true;
		}
	return false;
}
void defragment()
{
	int i,sum=0;
	sort(v.begin(),v.end());
	for (int i=0;i<v.size();i++)
	{
		int x=v[i].first.second-v[i].first.first;
		v[i].first.first=sum;
		sum+=x;
		v[i].first.second=sum;
	}
	return;
}
int main()
{
	int id=1;
	cin>>t>>m;
	for (int i=0;i<t;i++)
	{
		int k;
		string s;
		cin>>s;
		if (s=="alloc")
		{
			cin>>k;
			if (alloc(k,id)) id++;
		}
		if (s=="erase")
		{
			cin>>k;
			if (!clean(k))
				cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		}
		if (s[0]=='d')
		{
			defragment();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
template <typename _Tp> inline void read(_Tp&x){
    char ch;bool flag=0;x=0;
    while(ch=getchar(),!isdigit(ch))if(ch=='-')flag=1;
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    if(flag)x=-x;
}
using namespace std;
int main(){
    cout<<"1\n";
	cout<<"2\n";
	cout<<"NULL\n";
	cout<<"3\n";
    return 0;
}


#include <iostream>
#include <string>
#include <array>
using namespace std;
int main()
{
    std::array<int, 100> Arr{ 0 };
    int t, m;
    std::cin >> t >> m;

    int id = 1; // 标记着最远的编号，从1开始
    std::string Command;
    while (t--)
    {
        std::cin >> Command;
        if (Command[0] == 'a')  // "alloc"
        {
            int p;
            std::cin >> p;

            int cnt = 0, idx = 0;
            bool OK = false;
            for (int i = 0; i < m; ++i)
            {
                if (!Arr[i])
                {
                    ++cnt;  // 去找有多少个连续的0
                }
                else
                {
                    cnt = 0;    // 中断了就清零重来
                    idx = i + 1;
                }

                if (cnt == p)   // 依题意，找到了第一个能存放p个单位的就立马跳出
                {
                    OK = true;
                    break;
                }
            }

            if (OK)
            {   // 从idx开始涂连续的p个
                for (int i = idx; i < idx + p; ++i)
                {
                    Arr[i] = id;
                }

                // 这里要加一了
                std::cout << id++ << std::endl;
            }
            else
            {
                std::puts("NULL");
            }
        }
        else if (Command[0] == 'e') // "erase"
        {
            int p;
            std::cin >> p;

            if (p > id || p <= 0)   // 删除最大标号以外的或者删除1以下的均为非法
            {
                std::puts("ILLEGAL_ERASE_ARGUMENT");
            }
            else
            {
                int f = false;
                int i;
                for (i = 0; i < m; ++i)
                {
                    if (Arr[i] == p)    // 去找要被删去的第一个数的下标
                    {
                        break;
                    }
                }

                while (Arr[i] == p)
                {
                    Arr[i] = 0; // 清零即是删除
                    ++i;
                    f = true;   // 标记删除操作被执行了
                }

                if (!f) // 如果这一次删除没有做任何操作，那么这个删除也是无效的
                {
                    std::puts("ILLEGAL_ERASE_ARGUMENT");
                }
            }
        }
        else   // "defragment"
        {
            int idx = 0;
            for (int i = 0; i < m; ++i)
            {
                if (Arr[i]) // 如果非零，则存放在前面
                {
                    Arr[idx++] = Arr[i];
                }
            }
            for (int i = idx; i < m; ++i)   // 后面那部分都是零
            {
                Arr[i] = 0;
            }
        }
    }

    return 0;
}


#include <cstdio>

const int N = 105;

int t[N], tot, q, n;

int alloc(int len) {
	bool ok = false;
	int l = 0;
	for (int i = 1; i <= n; i++) {
		if (t[i] == 0) l++;
		else l = 0;
		if (l == len) {
			tot++;	ok = true;
			for (int j = 1; j <= l; j++) t[i - j + 1] = tot;
			break;
		}
	}
	if (ok) return tot;
	else return 0;
}

bool erase(int b) {
	if (b <= 0) return false;
	bool ok = false;
	for (int i = 1; i <= n; i++) {
		if (t[i] == b) {
			ok = true;
			for (int j = i; j <= n && t[j] == b; j++) t[j] = 0;
			break;
		}
	}
	return ok;
}

void defragment() {
	int zero = 0;
	for (int i = 1; i <= n; i++) {
		if (t[i] == 0) zero++;
		else { t[i - zero] = t[i]; if (zero > 0) t[i] = 0; }
	}
}

int main() {
	scanf("%d %d", &q, &n);
	for (int i = 1; i <= q; i++) {
		char s[15];
		scanf("%s", s + 1);
		if (s[1] == 'a') {
			int x;
			scanf("%d", &x);
			int z = alloc(x);
			if (z == 0) printf("NULL\n");
			else printf("%d\n", z);
		} else if (s[1] == 'e') {
			int x;
			scanf("%d", &x);
			bool z = erase(x);
			if (z == false) printf("ILLEGAL_ERASE_ARGUMENT\n");
		} else if (s[1] == 'd') {
			defragment();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,m,n,x,blk,mem[120],beg[120],nmem[120];
string cmd;
void al(){//内存分配：尽量靠左，O(n+m)
	if(n>m){
		cout<<"NULL"<<endl;
		return;
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
		cnt+=mem[i];
	if(cnt==0){
		cout<<++blk<<endl;
		for(int i=1;i<=n;i++){
			mem[i]=blk;
		}
		beg[blk]=1;
		return;
	}
	for(int i=n+1;i<=m;i++){
		cnt+=mem[i];
		cnt-=mem[i-n];
		if(cnt==0){
			cout<<++blk<<endl;
			for(int j=1;j<=n;j++){
				mem[i-n+j]=blk;
			}
			beg[blk]=1;
			return;
		}
	}
	cout<<"NULL"<<endl;
	return;
}
void er(){//删内存，O(m)
	if(x>blk){
		cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		return;
	}
	if(beg[x]==0){
		cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		return;
	}
	for(int i=beg[x];mem[i]==x;i++){
		mem[i]=0;
	}
	beg[x]=0;
}
void de(){//碎片清理，O(m)
	for(int i=1;i<=m;i++)
		nmem[i]=0;
	int nmemtop=0;
	for(int i=1;i<=m;i++){
		if(mem[i]){
			nmemtop++;
			nmem[nmemtop]=mem[i];
		}
	}
	for(int i=1;i<=m;i++)
		mem[i]=0;
	for(int i=1;i<=m;i++){
		mem[i]=nmem[i];
		if(mem[i]!=mem[i-1])
			beg[mem[i]]=i;
	}
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>t>>m;
	while(t--){
		cin>>cmd;
		if(cmd=="alloc"){
			cin>>n;
			al();
		}
		if(cmd=="erase"){
			cin>>x;
			er();
		}
		if(cmd=="defragment"){
			de();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,m,n,x,blk,mem[120],beg[120],nmem[120];
string cmd;
void al(){//内存分配：尽量靠左，O(n+m)
	if(n>m){
		cout<<"NULL"<<endl;
		return;
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
		cnt+=mem[i];
	if(cnt==0){
		cout<<++blk<<endl;
		for(int i=1;i<=n;i++){
			mem[i]=blk;
		}
		beg[blk]=1;
		return;
	}
	for(int i=n+1;i<=m;i++){
		cnt+=mem[i];
		cnt-=mem[i-n];
		if(cnt==0){
			cout<<++blk<<endl;
			for(int j=1;j<=n;j++){
				mem[i-n+j]=blk;
			}
			beg[blk]=i-n+1;
			return;
		}
	}
	cout<<"NULL"<<endl;
	return;
}
void er(){//删内存，O(m)
	if(x>blk||x<=0){
		cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		return;
	}
	if(beg[x]==0){
		cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		return;
	}
	for(int i=beg[x];mem[i]==x;i++){
		mem[i]=0;
	}
	beg[x]=0;
}
void de(){//碎片清理，O(m)
	for(int i=1;i<=m;i++)
		nmem[i]=0;
	int nmemtop=0;
	for(int i=1;i<=m;i++){
		if(mem[i]){
			nmemtop++;
			nmem[nmemtop]=mem[i];
		}
	}
	for(int i=1;i<=m;i++)
		mem[i]=0;
	for(int i=1;i<=m;i++){
		mem[i]=nmem[i];
		if(mem[i]!=mem[i-1])
			beg[mem[i]]=i;
	}
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int trsyyyyyyy;
	cin>>t>>m;
	while(t--){
		cin>>cmd;
		if(cmd=="alloc"){
			cin>>n;
			al();
		}
		if(cmd=="erase"){
			cin>>x;
			er();
		}
		if(cmd=="defragment"){
			de();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,m,n,x,blk,mem[120],beg[120],nmem[120];
string cmd;
void al(){//内存分配：尽量靠左，O(n+m)
	if(n>m){
		cout<<"NULL"<<endl;
		return;
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
		cnt+=mem[i];
	if(cnt==0){
		cout<<++blk<<endl;
		for(int i=1;i<=n;i++){
			mem[i]=blk;
		}
		beg[blk]=1;
		return;
	}
	for(int i=n+1;i<=m;i++){
		cnt+=mem[i];
		cnt-=mem[i-n];
		if(cnt==0){
			cout<<++blk<<endl;
			for(int j=1;j<=n;j++){
				mem[i-n+j]=blk;
			}
			beg[blk]=i-n+1;
			return;
		}
	}
	cout<<"NULL"<<endl;
	return;
}
void er(){//删内存，O(m)
	if(x>blk){
		cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		return;
	}
	if(beg[x]==0){
		cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		return;
	}
	for(int i=beg[x];mem[i]==x;i++){
		mem[i]=0;
	}
	beg[x]=0;
}
void de(){//碎片清理，O(m)
	for(int i=1;i<=m;i++)
		nmem[i]=0;
	int nmemtop=0;
	for(int i=1;i<=m;i++){
		if(mem[i]){
			nmemtop++;
			nmem[nmemtop]=mem[i];
		}
	}
	for(int i=1;i<=m;i++)
		mem[i]=0;
	for(int i=1;i<=m;i++){
		mem[i]=nmem[i];
		if(mem[i]!=mem[i-1])
			beg[mem[i]]=i;
	}
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>t>>m;
	while(t--){
		cin>>cmd;
		if(cmd=="alloc"){
			cin>>n;
			al();
		}
		if(cmd=="erase"){
			cin>>x;
			er();
		}
		if(cmd=="defragment"){
			de();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,m,n,x,blk,mem[120],beg[120],nmem[120];
string cmd;
void al(){//内存分配：尽量靠左，O(n+m)
	if(n>m){
		cout<<"NULL"<<endl;
		return;
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
		cnt+=mem[i];
	if(cnt==0){
		cout<<++blk<<endl;
		for(int i=1;i<=n;i++){
			mem[i]=blk;
		}
		beg[blk]=1;
		return;
	}
	for(int i=n+1;i<=m;i++){
		cnt+=mem[i];
		cnt-=mem[i-n];
		if(cnt==0){
			cout<<++blk<<endl;
			for(int j=1;j<=n;j++){
				mem[i-n+j]=blk;
			}
			beg[blk]=i-n+1;
			return;
		}
	}
	cout<<"NULL"<<endl;
	return;
}
void er(){//删内存，O(m)
	if(x>blk||x<=0){
		cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		return;
	}
	if(beg[x]==0){
		cout<<"ILLEGAL_ERASE_ARGUMENT"<<endl;
		return;
	}
	for(int i=beg[x];mem[i]==x;i++){
		mem[i]=0;
	}
	beg[x]=0;
}
void de(){//碎片清理，O(m)
	for(int i=1;i<=m;i++)
		nmem[i]=0;
	int nmemtop=0;
	for(int i=1;i<=m;i++){
		if(mem[i]){
			nmemtop++;
			nmem[nmemtop]=mem[i];
		}
	}
	for(int i=1;i<=m;i++)
		mem[i]=0;
	for(int i=1;i<=m;i++){
		mem[i]=nmem[i];
		if(mem[i]!=mem[i-1])
			beg[mem[i]]=i;
	}
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>t>>m;
	while(t--){
		cin>>cmd;
		if(cmd=="alloc"){
			cin>>n;
			al();
		}
		if(cmd=="erase"){
			cin>>x;
			er();
		}
		if(cmd=="defragment"){
			de();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;
int t,n;
int a[100];
int cnt;
int main(){
	cin>>t>>n;
	string s;
	while(t--){
		cin>>s;int x;
		if(s!="defragment")
		cin>>x;
		if(s=="alloc"){
			int tt=0;
			int en=-1;
			for(int i=0;i<n;i++){
				if(a[i])
				tt=0;
				else{
					tt++;
					if(tt==x){
						en=i;
						break;
					}
				}
			}
			if(en==-1){
				cout<<"NULL\n";
				continue;
			}
			cnt++;
			for(int i=en-x+1;i<=en;i++){
				a[i]=cnt;
			}
			cout<<cnt<<"\n";
		}
		if(s=="erase"){
			bool f=false;
			for(int i=0;i<n;i++)
			if(a[i]==x){
				f=true;
				a[i]=0;
			}
			if(!f){
				cout<<"ILLEGAL_ERASE_ARGUMENT\n";
				continue;
			}
		}
		if(s=="defragment"){
			for(int i=1;i<=cnt;i++){
				int aa=-1,j=0,tt=0;
				for(;j<n;j++){
					if(a[j]&&aa!=-1&&a[j]!=aa)
					break;
					if(aa==-1&&a[j])
					aa=a[j],tt++,a[j]=0;
					else
					if(aa!=-1&&aa==a[j])
					tt++,a[j]=0;
				}
				for(int k=0;k<n;k++){
					if(a[k]==0){
						for(int i1=k;i1<k+tt;i1++)
						a[i1]=aa;
						break;
					}
				}
			}
		}
	}
	re 0;
}


#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;
int t,n;
int a[100];
int cnt;
int main(){
	cin>>t>>n;
	string s;
	while(t--){
		cin>>s;int x;
		if(s!="defragment")
		cin>>x;
		if(s=="alloc"){
			int tt=0;
			int en=-1;
			for(int i=0;i<n;i++){
				if(a[i])
				tt=0;
				else{
					tt++;
					if(tt==x){
						en=i;
						break;
					}
				}
			}
			if(en==-1){
				cout<<"NULL\n";
				continue;
			}
			cnt++;
			for(int i=en-x+1;i<=en;i++){
				a[i]=cnt;
			}
			cout<<cnt<<"\n";
		}
		if(s=="erase"){
			if(x==0){
				cout<<"ILLEGAL_ERASE_ARGUMENT\n";
				continue;
			}

			bool f=false;
			for(int i=0;i<n;i++)
			if(a[i]==x){
				f=true;
				a[i]=0;
			}
			if(!f){
				cout<<"ILLEGAL_ERASE_ARGUMENT\n";
				continue;
			}
		}
		if(s=="defragment"){
			bool f[101];
			zero(f);
			for(int i=1;i<=cnt;i++){
				int aa=-1,j=0,tt=0;
				for(;j<n;j++){
					if(aa!=-1&&a[j]!=aa)
					break;
					if(aa==-1&&a[j]&&!f[a[j]])
					aa=a[j],tt++,a[j]=0;
					else
					if(aa!=-1&&aa==a[j])
					tt++,a[j]=0;
				}
				if(aa==-1)
				break;
				f[aa]=true;
				for(int k=0;k<n;k++){
					if(a[k]==0){
						for(int i1=k;i1<k+tt;i1++)
						a[i1]=aa;
						break;
					}
				}
			}
		}
	}
	re 0;
}


#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;
int t,n;
int a[100];
int cnt;
int main(){
	cin>>t>>n;
	string s;
	while(t--){
		cin>>s;int x;
		if(s!="defragment")
		cin>>x;
		if(s=="alloc"){
			int tt=0;
			int en=-1;
			for(int i=0;i<n;i++){
				if(a[i])
				tt=0;
				else{
					tt++;
					if(tt==x){
						en=i;
						break;
					}
				}
			}
			if(en==-1){
				cout<<"NULL\n";
				continue;
			}
			cnt++;
			for(int i=en-x+1;i<=en;i++){
				a[i]=cnt;
			}
			cout<<cnt<<"\n";
		}
		if(s=="erase"){
			bool f=false;
			for(int i=0;i<n;i++)
			if(a[i]==x){
				f=true;
				a[i]=0;
			}
			if(!f){
				cout<<"ILLEGAL_ERASE_ARGUMENT\n";
				continue;
			}
		}
		if(s=="defragment"){
			bool f[101];
			zero(f);
			for(int i=1;i<=cnt;i++){
				int aa=-1,j=0,tt=0;
				for(;j<n;j++){
					if(aa!=-1&&a[j]!=aa)
					break;
					if(aa==-1&&a[j]&&!f[a[j]])
					aa=a[j],tt++,a[j]=0;
					else
					if(aa!=-1&&aa==a[j])
					tt++,a[j]=0;
				}
				if(aa==-1)
				break;
				f[aa]=true;
				for(int k=0;k<n;k++){
					if(a[k]==0){
						for(int i1=k;i1<k+tt;i1++)
						a[i1]=aa;
						break;
					}
				}
			}
		}
	}
	re 0;
}


#include<bits/stdc++.h>

using namespace std;

int t,n,x, k;
string s;
int a[105];

int main() { //ifstream cin("t.in");

    cin>>t>>n;

    while (t--) {
        cin>>s;

        if (s[0]=='d') {
            int p=0;
            for (int i=1; i<=n; i++) {
                if (a[i]) a[++p]=a[i];
            }
            for (int i=p+1; i<=n; i++) a[i]=0;
            continue;
        }

        cin>>x;
        if (s[0]=='a') {
            int s=0;
            for (int i=1; i<=n && x; i++) {
                if (a[i]) s=0;
                else ++s;

                if (s==x) {
                    ++k;
                    while (x) a[i-x+1]=k, x--;
                }
            }

            if (x) cout<<"NULL\n";
            else cout<<k<<'\n';
        } else {
            bool u=0;
            for (int i=1; i<=n; i++) {
                if (a[i]==x) a[i]=0, u=1;
            }

            if (!u) cout<<"ILLEGAL_ERASE_ARGUMENT\n";
        }
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int t,n,x, k;
string s;
int a[105];

int main() {

    cin>>t>>n;

    while (t--) {
        cin>>s;

        if (s[0]=='d') {
            int p=0;
            for (int i=1; i<=n; i++) {
                if (a[i]) a[++p]=a[i], a[i]=0;
            }
            continue;
        }

        cin>>x;
        if (s[0]=='a') {
            int s=0;
            for (int i=1; i<=n && s!=x; i++) {
                if (a[i]) s=0;
                else ++s;

                if (s==x) {
                    ++k;
                    while (x) a[i-x+1]=k, x--;
                }
            }

            if (x) cout<<"NULL\n";
            else cout<<k<<'\n';
        } else {
            bool u=0;
            for (int i=1; i<=n; i++) {
                if (a[i]==x) a[i]=0, u=1;
            }

            if (!u) cout<<"ILLEGAL_ERASE_ARGUMENT\n";
        }

    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int t,n,x, k;
string s;
int a[105];

int main() {
    cin>>t>>n;

    while (t--) {
        cin>>s;

        if (s[0]=='d') { // defragmentare
            int p=0;
            for (int i=1; i<=n; i++) {
                if (a[i]) a[++p]=a[i];
            }
            for (int i=p+1; i<=n; i++) a[i]=0;
            continue;
        }

        cin>>x;
        if (s[0]=='a') { // alocam memorie
            int s=0;
            for (int i=1; i<=n && x; i++) {
                if (a[i]) s=0;
                else ++s;

                if (s==x) {
                    ++k;
                    while (x) a[i-x+1]=k, x--;
                }
            }

            if (x) cout<<"NULL\n";
            else cout<<k<<'\n';
        } else {    //stergem blocul de memorie x daca exista
            bool u=0;
            for (int i=1; i<=n; i++) {
                if (a[i]==x) a[i]=0, u=1;
            }

            if (!u || x<1) cout<<"ILLEGAL_ERASE_ARGUMENT\n";
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in inline
#define ll long long
const int N=2100;
in int read()
{
	int w=0,r=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')r=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		w=(w<<1)+(w<<3)+(ch^48);
		ch=getchar();
	}
	return w*r;
}

int T,m,id;

struct node
{
	int l,r,name,siz;
}nd[N],nv[N];
bool mark[N],flag[N],vis[N];

void part1()
{
	for(int i=1;i<=m;i++)
	{
		vis[i]=mark[i];
	}
	int n=read();
	int l=0,r=0,cnt=0;
	id++;
	for(int i=1;i<=m;i++)
	{
		if(vis[i]==1)
		{
			l=0;
			r=0;
			cnt=0;
		}
		if(vis[i]==0)
		{
			if(l==0)
			{
				l=i;
				r=i;
				cnt=1;
//				vis[i]=1;
			}
			else
			{
				cnt++;
				r++;
//				vis[i]=1;
			}

		}
		if(cnt==n)
		{
			nd[id].l=l;
			nd[id].r=r;
			nd[id].name=id;
			nd[id].siz=n;
			cout<<id<<endl;
//			flag[id]=1;
			for(int j=l;j<=r;j++)
			{
				mark[j]=1;
			}
			break;
		}
	}
	if(nd[id].l==0&&nd[id].r==0)
	{
		puts("NULL");
//		flag[id]=1;
		id--;
	}
}

void part2()
{
	int n=read();
//	if(n>m)
//	{
//
//	}
	if(id<n||n<1||flag[n]==1)
	{
		puts("ILLEGAL_ERASE_ARGUMENT");
		return ;
	}
	flag[n]=1;
	for(int i=nd[n].l;i<=nd[n].r;i++)
	{
		mark[i]=0;
	}
}

in bool cmp(node a,node b)
{
	return a.l<b.l;
}

void part3()
{
	for(int i=1;i<=id;i++)
	{
		nv[i]=nd[i];
	}
	sort(nv+1,nv+1+id,cmp);
	int last=1,num=0;
	for(int i=1;i<=id;i++)
	{
		int x=nv[i].name;
//		cout<<x<<endl;
		if(flag[x]==1)continue;
		nd[x].l=last;
		nd[x].r=nd[x].l+nd[x].siz-1;
		last=nd[x].r+1;
		num+=nd[x].siz;
	}
	for(int i=1;i<=num;i++)
	{
		mark[i]=1;
	}
	for(int i=num+1;i<=m;i++)
	{
		mark[i]=0;
	}
//	for(int i=1;i<=id;i++)
//	{
//		if(flag[i]==1)continue;
//		cout<<i<<" "<<nd[i].l<<" "<<nd[i].r<<endl;
//	}
}

int main()
{
//	freopen("2.in","r",stdin);
	T=read();
	m=read();
//	mark[0]=1;
//	mark[m+1]=1;
	for(int k=1;k<=T;k++)
	{
		string str;
		cin>>str;
		if(str=="alloc")
		{
			part1();
		}
		if(str=="erase")
		{
			part2();
		}
		if(str=="defragment")
		{
			part3();
		}
//		for(int i=1;i<=m;i++)
//		{
//			cout<<mark[i]<<" ";
//		}
//		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in inline
#define ll long long
const int N=210;
in int read()
{
	int w=0,r=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')r=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		w=(w<<1)+(w<<3)+(ch^48);
		ch=getchar();
	}
	return w*r;
}

int T,m,id;

struct node
{
	int l,r,name,siz;
}nd[N];
bool mark[N],flag[N];

void part1()
{
	int n=read();
	int l=0,r=0,cnt=0;
	id++;
	for(int i=1;i<=m;i++)
	{
		if(cnt==n)
		{
			nd[id].l=l;
			nd[id].r=r;
			nd[id].name=id;
			nd[id].siz=n;
			cout<<id<<endl;
			break;
		}
		if(mark[i]==1)
		{
			l=0;
			r=0;
			cnt=0;
		}
		if(mark[i]==0)
		{
			if(l==0)
			{
				l=i;
				r=i;
				cnt=1;
				mark[i]=1;
			}
			else
			{
				cnt++;
				r++;
				mark[i]=1;
			}

		}
	}
	if(nd[id].l==0&&nd[id].r==0)
	{
		puts("NULL");
		flag[id]=1;
		id--;
	}
}

void part2()
{
	int n=read();
	if(flag[n]==1)
	{
		puts("ILLEGAL_ERASE_ARGUMENT");
		return ;
	}
	flag[n]=1;
	for(int i=nd[n].l;i<=nd[n].r;i++)
	{
		mark[i]=0;
	}
}

void part3()
{
	int last=1,num=0;
	for(int i=1;i<=id;i++)
	{
		if(flag[i]==1)continue;
		nd[i].l=last;
		last=nd[i].r+1;
		nd[i].r=nd[i].l+nd[i].siz-1;
		num+=nd[i].siz;
	}
	for(int i=1;i<=num;i++)
	{
		mark[i]=1;
	}
	for(int i=num+1;i<=m;i++)
	{
		mark[i]=0;
	}
}

int main()
{
//	freopen("1.in","r",stdin);
	T=read();
	m=read();
	mark[0]=1;
	mark[m+1]=1;
	for(int k=1;k<=T;k++)
	{
		string str;
		cin>>str;
		if(str=="alloc")
		{
			part1();
		}
		if(str=="erase")
		{
			part2();
		}
		if(str=="defragment")
		{
			part3();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in inline
#define ll long long
const int N=210;
in int read()
{
	int w=0,r=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')r=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		w=(w<<1)+(w<<3)+(ch^48);
		ch=getchar();
	}
	return w*r;
}

int T,m,id;

struct node
{
	int l,r,name,siz;
}nd[N];
bool mark[N],flag[N],vis[N];

void part1()
{
	for(int i=1;i<=m;i++)
	{
		vis[i]=mark[i];
	}
	int n=read();
	int l=0,r=0,cnt=0;
	id++;
	for(int i=1;i<=m;i++)
	{
		if(vis[i]==1)
		{
			l=0;
			r=0;
			cnt=0;
		}
		if(vis[i]==0)
		{
			if(l==0)
			{
				l=i;
				r=i;
				cnt=1;
//				vis[i]=1;
			}
			else
			{
				cnt++;
				r++;
//				vis[i]=1;
			}

		}
		if(cnt==n)
		{
			nd[id].l=l;
			nd[id].r=r;
			nd[id].name=id;
			nd[id].siz=n;
			cout<<id<<endl;
			for(int j=l;j<=r;j++)
			{
				mark[j]=1;
			}
			break;
		}
	}
	if(nd[id].l==0&&nd[id].r==0)
	{
		puts("NULL");
		flag[id]=1;
		id--;
	}
}

void part2()
{
	int n=read();
	if(flag[n]==1||id<n)
	{
		puts("ILLEGAL_ERASE_ARGUMENT");
		return ;
	}
	flag[n]=1;
	for(int i=nd[n].l;i<=nd[n].r;i++)
	{
		mark[i]=0;
	}
}

void part3()
{
	int last=1,num=0;
	for(int i=1;i<=id;i++)
	{
		if(flag[i]==1)continue;
		nd[i].l=last;
		last=nd[i].r+1;
		nd[i].r=nd[i].l+nd[i].siz-1;
		num+=nd[i].siz;
	}
	for(int i=1;i<=num;i++)
	{
		mark[i]=1;
	}
	for(int i=num+1;i<=m;i++)
	{
		mark[i]=0;
	}
}

int main()
{
//	freopen("1.in","r",stdin);
	T=read();
	m=read();
//	mark[0]=1;
//	mark[m+1]=1;
	for(int k=1;k<=T;k++)
	{
		string str;
		cin>>str;
		if(str=="alloc")
		{
			part1();
		}
		if(str=="erase")
		{
			part2();
		}
		if(str=="defragment")
		{
			part3();
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in inline
#define ll long long
const int N=2100;
in int read()
{
	int w=0,r=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')r=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		w=(w<<1)+(w<<3)+(ch^48);
		ch=getchar();
	}
	return w*r;
}

int T,m,id;

struct node
{
	int l,r,name,siz;
}nd[N],nv[N];
bool mark[N],flag[N],vis[N];

void part1()
{
	for(int i=1;i<=m;i++)
	{
		vis[i]=mark[i];
	}
	int n=read();
	int l=0,r=0,cnt=0;
	id++;
	for(int i=1;i<=m;i++)
	{
		if(vis[i]==1)
		{
			l=0;
			r=0;
			cnt=0;
		}
		if(vis[i]==0)
		{
			if(l==0)
			{
				l=i;
				r=i;
				cnt=1;
//				vis[i]=1;
			}
			else
			{
				cnt++;
				r++;
//				vis[i]=1;
			}

		}
		if(cnt==n)
		{
			nd[id].l=l;
			nd[id].r=r;
			nd[id].name=id;
			nd[id].siz=n;
			cout<<id<<endl;
//			flag[id]=1;
			for(int j=l;j<=r;j++)
			{
				mark[j]=1;
			}
			break;
		}
	}
	if(nd[id].l==0&&nd[id].r==0)
	{
		puts("NULL");
//		flag[id]=1;
		id--;
	}
}

void part2()
{
	int n=read();
	if(flag[n]==1||id<n||n<1)
	{
		puts("ILLEGAL_ERASE_ARGUMENT");
		return ;
	}
	flag[n]=1;
	for(int i=nd[n].l;i<=nd[n].r;i++)
	{
		mark[i]=0;
	}
}

in bool cmp(node a,node b)
{
	return a.l<b.l;
}

void part3()
{
	for(int i=1;i<=id;i++)
	{
		nv[i]=nd[i];
	}
	sort(nv+1,nv+1+id,cmp);
	int last=1,num=0;
	for(int i=1;i<=id;i++)
	{
		int x=nv[i].name;
//		cout<<x<<endl;
		if(flag[x]==1)continue;
		nd[x].l=last;
		last=nd[x].r+1;
		nd[x].r=nd[x].l+nd[x].siz-1;
		num+=nd[x].siz;
	}
	for(int i=1;i<=num;i++)
	{
		mark[i]=1;
	}
	for(int i=num+1;i<=m;i++)
	{
		mark[i]=0;
	}
}

int main()
{
//	freopen("1.in","r",stdin);
	T=read();
	m=read();
//	mark[0]=1;
//	mark[m+1]=1;
	for(int k=1;k<=T;k++)
	{
		string str;
		cin>>str;
		if(str=="alloc")
		{
			part1();
		}
		if(str=="erase")
		{
			part2();
		}
		if(str=="defragment")
		{
			part3();
		}
//		for(int i=1;i<=m;i++)
//		{
//			cout<<mark[i]<<" ";
//		}
//		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in inline
#define ll long long
const int N=2100;
in int read()
{
	int w=0,r=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')r=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		w=(w<<1)+(w<<3)+(ch^48);
		ch=getchar();
	}
	return w*r;
}

int T,m,id;

struct node
{
	int l,r,name,siz;
}nd[N];
bool mark[N],flag[N],vis[N];

void part1()
{
	for(int i=1;i<=m;i++)
	{
		vis[i]=mark[i];
	}
	int n=read();
	int l=0,r=0,cnt=0;
	id++;
	for(int i=1;i<=m;i++)
	{
		if(vis[i]==1)
		{
			l=0;
			r=0;
			cnt=0;
		}
		if(vis[i]==0)
		{
			if(l==0)
			{
				l=i;
				r=i;
				cnt=1;
//				vis[i]=1;
			}
			else
			{
				cnt++;
				r++;
//				vis[i]=1;
			}

		}
		if(cnt==n)
		{
			nd[id].l=l;
			nd[id].r=r;
			nd[id].name=id;
			nd[id].siz=n;
			cout<<id<<endl;
//			flag[id]=1;
			for(int j=l;j<=r;j++)
			{
				mark[j]=1;
			}
			break;
		}
	}
	if(nd[id].l==0&&nd[id].r==0)
	{
		puts("NULL");
//		flag[id]=1;
		id--;
	}
}

void part2()
{
	int n=read();
	if(flag[n]==1||id<n||n<1)
	{
		puts("ILLEGAL_ERASE_ARGUMENT");
		return ;
	}
	flag[n]=1;
	for(int i=nd[n].l;i<=nd[n].r;i++)
	{
		mark[i]=0;
	}
}

void part3()
{
	int last=1,num=0;
	for(int i=1;i<=id;i++)
	{
		if(flag[i]==1)continue;
		nd[i].l=last;
		last=nd[i].r+1;
		nd[i].r=nd[i].l+nd[i].siz-1;
		num+=nd[i].siz;
	}
	for(int i=1;i<=num;i++)
	{
		mark[i]=1;
	}
	for(int i=num+1;i<=m;i++)
	{
		mark[i]=0;
	}
}

int main()
{
//	freopen("1.in","r",stdin);
	T=read();
	m=read();
//	mark[0]=1;
//	mark[m+1]=1;
	for(int k=1;k<=T;k++)
	{
		string str;
		cin>>str;
		if(str=="alloc")
		{
			part1();
		}
		if(str=="erase")
		{
			part2();
		}
		if(str=="defragment")
		{
			part3();
		}
//		for(int i=1;i<=m;i++)
//		{
//			cout<<mark[i]<<" ";
//		}
//		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define in inline
#define ll long long
const int N=2100;
in int read()
{
	int w=0,r=1;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-')r=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		w=(w<<1)+(w<<3)+(ch^48);
		ch=getchar();
	}
	return w*r;
}

int T,m,id;

struct node
{
	int l,r,name,siz;
}nd[N];
bool mark[N],flag[N],vis[N];

void part1()
{
	for(int i=1;i<=m;i++)
	{
		vis[i]=mark[i];
	}
	int n=read();
	int l=0,r=0,cnt=0;
	id++;
	for(int i=1;i<=m;i++)
	{
		if(vis[i]==1)
		{
			l=0;
			r=0;
			cnt=0;
		}
		if(vis[i]==0)
		{
			if(l==0)
			{
				l=i;
				r=i;
				cnt=1;
//				vis[i]=1;
			}
			else
			{
				cnt++;
				r++;
//				vis[i]=1;
			}

		}
		if(cnt==n)
		{
			nd[id].l=l;
			nd[id].r=r;
			nd[id].name=id;
			nd[id].siz=n;
			cout<<id<<endl;
//			flag[id]=1;
			for(int j=l;j<=r;j++)
			{
				mark[j]=1;
			}
			break;
		}
	}
	if(nd[id].l==0&&nd[id].r==0)
	{
		puts("NULL");
//		flag[id]=1;
		id--;
	}
}

void part2()
{
	int n=read();
	if(flag[n]==1||id<n||n<1)
	{
		puts("ILLEGAL_ERASE_ARGUMENT");
		return ;
	}
	flag[n]=1;
	for(int i=nd[n].l;i<=nd[n].r;i++)
	{
		mark[i]=0;
	}
}

void part3()
{
	int last=1,num=0;
	for(int i=1;i<=id;i++)
	{
		if(flag[i]==1)continue;
		nd[i].l=last;
		last=nd[i].r+1;
		nd[i].r=nd[i].l+nd[i].siz-1;
		num+=nd[i].siz;
	}
	for(int i=1;i<=min(num,m);i++)
	{
		mark[i]=1;
	}
	for(int i=num+1;i<=m;i++)
	{
		mark[i]=0;
	}
}

int main()
{
//	freopen("1.in","r",stdin);
	T=read();
	m=read();
//	mark[0]=1;
//	mark[m+1]=1;
	for(int k=1;k<=T;k++)
	{
		string str;
		cin>>str;
		if(str=="alloc")
		{
			part1();
		}
		if(str=="erase")
		{
			part2();
		}
		if(str=="defragment")
		{
			part3();
		}
//		for(int i=1;i<=m;i++)
//		{
//			cout<<mark[i]<<" ";
//		}
//		puts("");
	}
	return 0;
}