#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, f = 0, i, on = 0;
  cin >> n >> m;
  map<long long, long long> mp;
  for (i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    if (x == 1) on = 1;
    if (mp[x] == 0)
      mp[x] = y;
    else {
      if (mp[x] != y && x <= 3) f = -1;
    }
  }
  if (mp[1] == 0 && on == 1) f = -1;
  if (f == -1)
    cout << -1 << "\n";
  else {
    for (i = 0; i < n; i++) {
      if (i == 0) {
        if (mp[1] != 0)
          cout << mp[1];
        else
          cout << 1;
      } else {
        if (mp[i + 1] != 0)
          cout << mp[i + 1];
        else
          cout << 0;
      }
    }
  }
  return 0;
}
