#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c;
  cin >> n >> m;
  vector<int> v(n, -1);
  if (m == 0) {
    cout << -1;
    return 0;
  }
  while (m--) {
    cin >> s >> c;
    if (v[s - 1] == -1 || v[s - 1] == c)
      v[s - 1] = c;
    else {
      cout << -1;
      return 0;
    }
  }
  if (n == 1 && v[0] == 0) {
    cout << 0;
    return 0;
  }
  if (v[0] == -1 || v[0] == 0) {
    cout << -1;
    return 0;
  }
  int result = 0;
  for (auto x : v) {
    result = result * 10 + (x == -1 ? 0 : x);
  }
  cout << result;
}
