#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], b[N];
int val[N];
int main() {
  int n, m;
  cin >> n >> m;
  int ok = 1;
  for (int i = 1; i <= 3; ++i) val[i] = -1;
  for (int i = 1; i <= m; ++i) {
    cin >> a[i] >> b[i];
    if (val[a[i]] == -1 || val[a[i]] == b[i])
      val[a[i]] = b[i];
    else
      ok = 0;
  }
  if (val[1] == 0) ok = 0;
  if (!ok) {
    cout << "-1\n";
  } else {
    if (val[1] == -1)
      cout << 1;
    else
      cout << val[1];
    for (int i = 2; i <= n; ++i) {
      if (val[i] != -1)
        cout << val[i];
      else
        cout << 0;
    }
    cout << '\n';
  }
  return 0;
}
