#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long LINF = 1LL << 60;
const int INF = 1 << 30;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] != -1 && a[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    } else {
      a[s - 1] = c;
    }
  }
  int ans = 0;
  if (a[0] == 0 && n != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (a[n - i] == -1) {
      if (n - i == n - 1) {
        ans += pow(10, n - i);
      }
    } else {
      ans += a[n - i] * pow(10, i - 1);
    }
  }
  cout << ans << endl;
  return 0;
}
