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