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