#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void floatOutPutSetup() {
  cout << fixed;
  cout << setprecision(10);
}
int main() {
  int n, m, ts, tc;
  cin >> n >> m;
  int s[m], c[m], a[n + 1];
  for (int i = 0; i < (n + 1); ++i) {
    a[i] = -1;
  }
  for (int i = 0; i < (m); ++i) {
    cin >> ts >> tc;
    if (a[ts] == -1 || a[ts] == tc)
      a[ts] = tc;
    else if (a[ts] != tc) {
      cout << -1;
      return 0;
    }
  }
  if (a[1] == -1) {
    if (n == 1)
      cout << 0;
    else
      cout << 1;
  } else if (a[1] == 0) {
    cout << -1;
    return 0;
  } else {
    cout << a[1];
  }
  for (int i = 2; i <= n; i++) {
    if (a[i] == -1)
      cout << 0;
    else {
      cout << a[i];
    }
  }
  return 0;
}
