#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int s[M];
  int c[M];
  int a[N];
  for (long long i = 0; i < (N); i++) a[i] = -1;
  for (long long i = 0; i < (M); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (long long i = 0; i < (M); i++) {
    if (a[s[i]] != -1) {
      if (a[s[i]] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
    a[s[i]] = c[i];
  }
  if (N == 1 && a[0] == -1) {
    cout << 0 << endl;
    return 0;
  }
  if (a[0] != 0) {
    if (a[0] == -1) a[0] = 1;
    for (long long i = (1); i < (N); i++)
      if (a[i] == -1) a[i] = 0;
  } else {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 0; i < (N); i++) cout << a[i];
  cout << endl;
  return 0;
}
