#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int MOD = 1e9 + 7;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> v(3, -1);
  bool f = false;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (v[a] != -1 && b != v[a]) {
      f = true;
    }
    if (a == 0 && b == 0) {
      f = true;
    }
    v[a] = b;
  }
  if (f) {
    cout << (-1) << endl;
    ;
    return;
  }
  if (n == 3) {
    cout << (v[0] != -1 ? v[0] : 1) << (v[1] != -1 ? v[1] : 0)
         << (v[2] != -1 ? v[2] : 0) << endl;
  } else if (n == 2) {
    cout << (v[0] != -1 ? v[0] : 1) << (v[1] != -1 ? v[1] : 0) << endl;
  } else {
    cout << (v[0] != -1 ? v[0] : 0) << endl;
  }
}
int main() {
  solve();
  return 0;
}
