#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> d(n, -1);
  bool flg = true;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (d[n - s] == -1)
      d[n - s] = c;
    else {
      if (d[n - s] == c)
        continue;
      else {
        flg = false;
        break;
      }
    }
  }
  if (n > 1 && d[n - 1] == 0) flg = false;
  int ans = 0;
  if (flg) {
    if (d[n - 1] == -1) {
      d[n - 1] = 1;
    }
    for (int i = 0; i < (n - 1); i++) {
      if (d[i] == -1) d[i] = 0;
    }
    for (int i = n - 1; i >= 0; i--) {
      ans += d[i];
      ans *= 10;
    }
    ans /= 10;
  }
  if (flg)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
