#include <iostream>
using namespace std;
#define LL long long

#include <algorithm>
#include <vector>
void _150() {
    LL n;
    cin >> n;

    // int p[8];
    // int q[8];
    int temp;
    vector<int> p, q;
    vector<int> perm_base;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        p.push_back(temp);
        perm_base.push_back(i + 1);
    }
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        q.push_back(temp);
    }

    LL a, b, index;
    a = -1;
    b = -1;
    index = 0;
    do {
        if (perm_base == p) {
            a = index;
        }

        if (perm_base == q) {
            b = index;
        }

        if (a != -1 && b != -1) {
            break;
        }

        index++;
    } while (next_permutation(perm_base.begin(), perm_base.end()));

    cout << abs(a - b) << endl;
}

#include <string>
void _151() {
    int n, m;
    cin >> n >> m;
    int p[100000] = {0};
    int correct[100000] = {0};
    int penalty_counts[100000] = {0};
    string temp;
    int correct_count = 0;
    for (int i = 0; i < m; ++i) {
        cin >> p[i] >> temp;
        if (temp == "AC") {
            if (correct[p[i] - 1] != 1) {
                correct_count++;
                correct[p[i] - 1] = 1;
            }
        } else {
            if (correct[p[i] - 1] != 1) {
                penalty_counts[p[i] - 1]++;
            }
        }
    }
    int penalty_count = 0;
    for (int i = 0; i < n; ++i) {
        if (correct[i] == 1) {
            penalty_count += penalty_counts[i];
        }
    }
    cout << correct_count << " " << penalty_count << endl;
}

#include <limits>
void _152_() { 
    int n;
    cin >> n;
    int temp;
    vector<int> p;
    int min_val = numeric_limits<int>::max();
    int count = 0;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        if (min_val >= temp) {
            min_val = temp;
            count++;
        }
    }
    cout << count << endl;
}

void _153() {
    int n, k;
    cin >> n >> k;

    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

    if (n <= k) {
        cout << 0 << endl;
        return;
    }

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

    int num_monsters = n - k;
    LL count = 0;
    for (int i = 0; i < num_monsters; ++i) {
        count += h[i];
    }
    cout << count << endl;
}

#include <set>
void _154() {
    int n;
    cin >> n;
    int temp;
    set<int> b;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        b.insert(temp);
    }

    if (b.size() != n) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

}

#include <map>
void _155() {
    int n;
    cin >> n;

    string temp;
    map<string, int> data;
    vector<string>::iterator itr;
    vector<int> counts;
    int prev_count, temp_count;
    for (int i = 0; i < n; ++i) { 
        cin >> temp;
        temp_count = data[temp];
        data[temp] = ++temp_count;
    }

    int max_count = 0;
    vector<string> candidate;
    for (auto itr = data.begin(); itr != data.end(); ++itr) {
        // cout << itr->first << " " << itr->second << " " << max_count << endl;
        if (itr->second > max_count) {
            max_count = itr->second;
            candidate.clear();
            candidate.push_back(itr->first);
        } else if (itr->second == max_count) {
            candidate.push_back(itr->first);
        }
    }

    // cout << candidate.size() << endl;
    sort(candidate.begin(), candidate.end());
    for (int i = 0; i < candidate.size(); ++i) {
        cout << candidate[i] << endl;
    }
}

#include <cfenv>
#include <cmath>
void _156() {
    int n;
    cin >> n;
    vector<int> x(n);
    int temp;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        sum += temp;
        x[i] = temp;
    }

    int p = std::round((float)sum / n);
    LL result = 0;
    for (int i = 0; i < n; ++i) {
        result += pow(x[i] - p, 2);
    }
    cout << result << endl;
}

void _157() {
    int n, m;
    cin >> n >> m;

    if (n == 1 && m == 0) {
        cout << 0 << endl;
        return;
    }
    char result[4] = "aaa";
    result[n] = 0;
    int index;
    char temp;
    bool    error = false;
    for (int i = 0; i < m; ++i) {
        cin >> index >> temp;
        if ((index == 1) && (temp == '0') && (n != 1)) {
            error = true;
            continue;
        }
        if ((result[index - 1] != 'a') && (result[index - 1] != temp)) {
            error = true;
            continue;
        }
        result[index - 1] = temp;
    }

    if (error) {
        cout << -1 << endl;
        return;
    }

    for (int i = 0; i < n; ++i) {
        if (result[i] == 'a') {
            if (i == 0) {
                result[i] = '1';
            } else {
                result[i] = '0';
            }
        }
    }

    cout << result << endl;
}

int main()
{
    _157();
    return 0;
}



Measured memory_bytes: 256