#include <bits/stdc++.h>
using namespace std;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T> >;
template <class T = int>
void print(vector<T> v) {
  for (auto a : v) cout << a << " ";
  cout << endl;
}
bool ok = true;
long long n, m, a[4];
void init() {
  cin >> n >> m;
  for (long long i = ((long long)(1)); i <= ((long long)(n)); i++) a[i] = -1;
}
int main(void) {
  init();
  for (long long i = 0; i < ((long long)(m)); i++) {
    int s, c;
    cin >> s >> c;
    if (a[s] == -1) {
      a[s] = c;
    } else {
      if (a[s] != c) ok = false;
    }
  }
  if (n == 1) {
    if (a[1] == -1) {
      cout << 0;
    } else {
      cout << a[1];
    }
    cout << endl;
    return 0;
  }
  if (a[1] == 0) ok = false;
  if (ok) {
    if (a[1] == -1) {
      cout << 1;
    } else {
      cout << a[1];
    }
    for (long long i = ((long long)(2)); i <= ((long long)(n)); i++) {
      if (a[i] == -1) {
        cout << 0;
      } else {
        cout << a[i];
      }
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
