#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long a[4];
  a[0] = a[1] = a[2] = a[3] = -1;
  bool b = 1;
  while (m--) {
    long long s, c;
    cin >> s >> c;
    if (a[s] == -1 || a[s] == c) {
      a[s] = c;
    } else
      b = 0;
  }
  if (a[1] == 0 && n > 1) b = 0;
  if (!b)
    cout << -1;
  else {
    for (long long i = 1; i <= n; i++) {
      if (a[i] == -1) a[i] = 0;
      cout << a[i];
    }
  }
  cout << '\n';
}
