#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans;
  ans = 0;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  int x[n];
  for (int i = 0; i < n; i++) {
    x[i] = -1;
  }
  for (int i = 0; i < m; i++) {
    if (s[i] == 1 && c[i] == 0) {
      ans = -1;
      break;
    }
    if (x[s[i] - 1] == -1) {
      x[s[i] - 1] = c[i];
    } else if (x[s[i] - 1] != c[i]) {
      ans = -1;
      break;
    }
  }
  if (ans != -1) {
    if (x[0] == -1) {
      x[0] = 1;
    }
    for (int i = 0; i < n; i++) {
      if (x[i] == -1) {
        x[i] = 0;
      }
      ans += x[i] * pow(10, n - i - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
