#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[3] = {-1, -1, -1};
  int n;
  cin >> n;
  int m;
  cin >> m;
  for (; m--;) {
    int s, c;
    cin >> s >> c;
    --s;
    if (~a[s] and a[s] != c) {
      cout << -1 << "\n";
      return 0;
    }
    a[s] = c;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans *= 10;
    int now = a[i];
    if (!~now) {
      if (i)
        now = 0;
      else
        now = 1;
    }
    ans += now;
  }
  if (n > 1 and a[0] == 0) {
    cout << -1 << "\n";
  } else
    cout << ans << "\n";
}
