#include <bits/stdc++.h>
using namespace std;
double pi = 3.141592653589793;
long long mod = 1000000007;
long long INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
long long llmax = 9223372036854775807;
long long llmin = -9223372036854775807;
int main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vector<int> s(m), c(m);
  vector<int> v(n, -1);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (v[s[i] - 1] == -1 || v[s[i] - 1] == c[i]) {
      v[s[i] - 1] = c[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (v[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (v[i] == -1) {
      if (i == 0) {
        v[i] = 1;
      } else {
        v[i] = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    ans += v[i] * pow(10, n - i - 1);
  }
  cout << ans << endl;
}
