#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 4;
int n, m, k;
int a[N];
string str;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  memset(a, -1, sizeof(a));
  cin >> n >> m;
  int wrong = 0;
  while (m--) {
    int x, y;
    cin >> x >> y;
    if (a[x] != -1 && a[x] != y)
      wrong = 1;
    else if (a[x] == -1 || a[x] == y)
      a[x] = y;
  }
  if ((n == 3 && a[1] <= 0) || (n == 2 && (a[1] <= 0 || a[3] != -1)) ||
      (n == 1 && (a[1] == -1 || a[2] != -1 || a[3] != -1)))
    wrong = 1;
  if (wrong)
    cout << -1 << endl;
  else {
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1)
        cout << 0;
      else
        cout << a[i];
    }
  }
  return 0;
}
