#include <bits/stdc++.h>
using namespace std;
void mahakal() {}
int main() {
  long long n, m;
  cin >> n >> m;
  map<long long, long long> mp;
  bool flag = 0;
  for (long long i = 0, a, b; i < m; i++) {
    cin >> a >> b;
    if (mp.count(a) > 0 && mp[a] != b) {
      flag = 1;
    } else {
      mp[a] = b;
    }
  }
  if (flag)
    cout << -1 << endl;
  else {
    for (long long i = 1; i <= n; i++) {
      if (mp.count(i) > 0) {
        if (mp[i] == 0 && n != 1) {
          cout << -1 << endl;
          return 0;
        }
        cout << mp[i];
      } else {
        if (i == 1)
          cout << 1;
        else
          cout << 0;
      }
    }
  }
  return 0;
}
