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