#include <iostream>
#include <string>

using namespace std;

int main() {
    int a = -2,b = -2,c = -2;
    int n,m;
    cin >> n;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int d,e;
        cin >> d;
        cin >> e;
        switch (d)
        {
        case 1:
            if (a != -2)
            {
                a = e;
            } else
            {
                if (a != e) {
                    std::cout << "-1" << endl;
                    return 0;
                }
            }
            break;
        case 2:
            if (b != -2) {
                b = e;
            } else {
                if (b != e)
                {
                    std::cout << "-1" << endl;
                    return 0;
                }
            }
            break;
        case 3:
            if (c != -2)
            {
                c = e;
            } else {
                if (c != e)
                {
                    std::cout << "-1" << endl;
                    return 0;
                }
                
            }
            break;
        default:
            break;
        }
    }
    if (a == -2)
    {
        a = 0;
    }
    if (b == -2)
    {
        b = 0;
    }
    if (c == -2)
    {
        c = 0;
    }
    int ret = 0;
    ret += (a * 100);
    ret += (b * 10);
    ret += c;
    if (to_string(ret).length != n) 
    {
        cout << "-1" << endl;
    }
    else {
        cout << ret << endl;
    }
    return 0;
}