#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 1001001001;
int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  vector<int> c(n, -1);
  for (int i = 0; i <= m - 1; ++i) {
    int si, ci;
    cin >> si >> ci;
    si--;
    if (c[si] != -1) {
      if (ci != c[si]) {
        puts("-1");
        return 0;
      }
    }
    c[si] = ci;
  }
  for (int i = 0; i <= n - 1; ++i) {
    if (c[i] != -1) {
      ans += c[i] * pow(10, n - 1 - i);
    }
  }
  if (n > 1 && c[0] == 0) {
    puts("-1");
    return 0;
  }
  cout << ans << endl;
  return 0;
}
