#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  } else {
    vector<pair<int, int>> vec(m);
    for (int i = 0; i < m; i++) cin >> vec.at(i).first >> vec.at(i).second;
    sort(vec.begin(), vec.end());
    int x = 0;
    bool finished = false;
    if (vec.at(0).first == 1 && vec.at(0).second == 0)
      cout << -1 << endl;
    else {
      if (vec.at(0).first > 1) x += pow(10, n - 1);
      if (m == 1)
        cout << x + (pow(10, n - vec.at(0).first) * vec.at(0).second) << endl;
      else {
        for (int i = 1; i < m; i++) {
          if (vec.at(i).first == vec.at(i - 1).first) {
            if (vec.at(i).second != vec.at(i - 1).second) {
              finished = true;
              break;
            }
          } else
            x += (pow(10, n - vec.at(i - 1).first) * vec.at(i - 1).second);
        }
        x += (pow(10, n - vec.at(m - 1).first) * vec.at(m - 1).second);
        if (finished == true)
          cout << -1 << endl;
        else
          cout << x << endl;
      }
    }
  }
}
