#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long fceil(long long a, long long b) {
  return (a % b == 0 ? a / b : a / b + 1);
}
int main() {
  int n, m, s, c, ans = 0, a[3] = {-1, -1, -1};
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (a[s - 1] >= 0 && a[s - 1] != c || n > 1 && s == 1 && c == 0) {
      ans = -1;
      break;
    }
    a[s - 1] = c;
  }
  if (ans == 0) {
    if (a[0] == -1 && m > 0) a[0] = 1;
    for (int i = 0; i < n; i++) {
      ans = ans * 10 + (a[i] < 0 ? 0 : a[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
