#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  bool frag = true;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] != -1 && a[s - 1] != c) frag = false;
    a[s - 1] = c;
  }
  if (n == 1)
    cout << max(0, a[0]) << endl;
  else {
    if (a[0] == 0) frag = false;
    if (frag) {
      for (int i = 0; i < (n); i++) {
        if (i == 0)
          cout << max(1, a[i]);
        else {
          if (a[i] == -1)
            cout << 0;
          else
            cout << a[i];
        }
      }
      cout << endl;
    } else
      cout << -1 << endl;
  }
}
