#include <bits/stdc++.h>
using namespace std;
void run() {
  int n, m, i;
  cin >> n >> m;
  vector<int> ret(n, 0);
  vector<int> used(n, -1);
  for (i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (used[n - s] > -1 && used[n - s] != c) {
      cout << "-1" << endl;
      return;
    }
    if (s == n && n > 0 && c == 0) {
      cout << "-1" << endl;
      return;
    }
    used[n - s] = c;
    ret[n - s] = c;
  }
  int x = 0;
  for (i = n - 1; i >= 0; i--) {
    x = x * 10 + ret[i];
  }
  int digs = 0, xx = x;
  while (xx > 0) {
    xx /= 10;
    digs++;
  }
  if (digs != n) {
    cout << "-1" << endl;
    return;
  }
  cout << x << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) {
    run();
  }
}
