#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> vec(n, -1);
  for (int i = 0; i < (m); i++) {
    int x, y;
    cin >> x >> y;
    x--;
    if (vec[x] != -1 && vec[x] != y) {
      cout << -1 << endl;
      return 0;
    } else {
      vec[x] = y;
    }
  }
  if (n == 1 && vec[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < (pow(10, n)); i++) {
    int x = i;
    int keta = 0;
    vector<int> tmp;
    while (x) {
      keta++;
      tmp.push_back(x % 10);
      x /= 10;
    }
    if (keta != n) continue;
    reverse(tmp.begin(), tmp.end());
    bool flag = true;
    for (int i = 0; i < (n); i++) {
      if (vec[i] != -1 && vec[i] != tmp[i]) flag = false;
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
