#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max();
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N, 0);
  int f = 1;
  for (int i = 0; i < (M); i++) {
    int ss, cc;
    cin >> ss >> cc;
    if ((a[ss - 1] == 0) || (a[ss - 1] == cc)) {
      if (ss == 1 && cc == 0) {
        cout << -1 << endl;
        a[0] = -1;
        break;
      }
      a[ss - 1] = cc;
    } else {
      cout << -1 << endl;
      a[0] = -1;
      break;
    }
  }
  if (a[0] == -1) {
    return 0;
  }
  if (a[0] == 0) {
    a[0] = 1;
  }
  int ans = 0;
  for (int i = 0; i < (N); i++) {
    ans += pow(10, N - i - 1) * a[i];
  }
  cout << ans << endl;
  return 0;
}
