#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int func(vector<int> &v) {
  int cnt = 0;
  for (int i = 0; i < v.size(); i++) {
    cnt = cnt + (v[i] * pow(10, v.size() - i - 1));
  }
  return cnt;
}
int main(void) {
  fast();
  int a, b;
  int m, n;
  cin >> n >> m;
  vector<int> v(n, -1);
  if (n == 1 && m == 0) {
    cout << 0 << "\n";
    return 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    if (v[a - 1] == -1) {
      v[a - 1] = b;
    } else if (v[a - 1] != -1 && v[a - 1] != b) {
      cout << -1 << "\n";
      return 0;
    }
  }
  if (n == 1 && m == 0) {
    cout << 0 << "\n";
    return 0;
  } else if (n == 1 && m != 0) {
    cout << v[0] << "\n";
    return 0;
  }
  if (v[0] == -1) {
    v[0] == 1;
  } else if (v[0] == 0) {
    cout << -1 << "\n";
    return 0;
  }
  for (int i = 1; i < v.size(); i++) {
    if (v[i] == -1) {
      v[i] = 0;
    }
  }
  cout << func(v) << "\n";
  return 0;
}
