#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int a[n];
  memset((a), -1, sizeof(a));
  int flg = true;
  for (long long i = 0; i < (long long)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] == -1)
      a[s - 1] = c;
    else if (a[s - 1] != c) {
      flg = false;
      break;
    }
  }
  if (flg && n == 1) {
    cout << 0 << endl;
  } else if (flg && a[0] != 0) {
    for (long long i = 0; i < (long long)(n); i++) {
      if (i == 0) {
        if (a[i] == -1)
          cout << 1;
        else
          cout << a[i];
      } else {
        if (a[i] == -1)
          cout << 0;
        else
          cout << a[i];
      }
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
