#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  long long n;
  cin >> n;
  long long m;
  long long a[4];
  a[0] = a[1] = a[2] = a[3] = -1;
  cin >> m;
  long long f = 1;
  while (m--) {
    long long x, y;
    cin >> x >> y;
    if (f) {
      if (a[x] != -1 && a[x] != y)
        f = 0;
      else
        a[x] = y;
    }
  }
  long long i;
  if (f == 0 || a[1] == 0)
    cout << "-1";
  else {
    if (a[1] == -1 && n > 1)
      a[1] = 1;
    else if (a[1] == -1 && n == 1)
      a[1] = 0;
    for (i = 2; i <= n; i++)
      if (a[i] == -1) a[i] = 0;
    for (i = 1; i <= n; i++) cout << a[i];
  }
}
