#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> vec;
int get_mx() {
  int ans = 0;
  int cnt = 3;
  int i = 1;
  while (cnt) {
    ans += 9 * i;
    cnt--;
    i *= 10;
  }
  return ans;
}
bool check(int num) {
  vector<int> r(n + 1, 0);
  int i = n;
  while (num) {
    r[i] = num % 10;
    num /= 10;
    i--;
  }
  if (n > 1 && vec[1] == 0) {
    return false;
  }
  bool ok = true;
  for (int i = 1; i < n + 1; i++) {
    if (vec[i] != -1) {
      if (vec[i] != r[i]) {
        ok = false;
        break;
      }
    }
  }
  return ok;
}
int main() {
  cin >> n >> m;
  vec.resize(n + 1, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (vec[s] != -1) {
      if (vec[s] != c) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      if (c == 0 && s != 1) {
        cout << -1 << endl;
        return 0;
      }
      vec[s] = c;
    }
  }
  int mx = get_mx();
  int ans = -1;
  for (int i = 0; i < mx; i++) {
    if (check(i)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
