#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    if (n == 1)
      cout << 0;
    else
      cout << pow(10, n - 1);
  } else {
    map<int, int> se;
    int val = 0;
    for (int i = 0; i < (m); i++) {
      int s, c;
      cin >> s >> c;
      if (se.find(s) == se.end()) {
        if (s == 1 && c == 0) {
          cout << -1;
          return 0;
        }
        val += c * pow(10, (n - s + 1) - 1);
        se[s] = c;
      } else if (se[s] != c) {
        cout << -1;
        return 0;
      }
    }
    if (n == 1) {
      cout << val;
    } else {
      if (val < pow(10, n - 1)) val += pow(10, n - 1);
      cout << val;
    }
  }
  return 0;
}
