#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int dig[n];
  for (int i = 0; i < (n); ++i) {
    dig[i] = -1;
  }
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    if (dig[n - s] != -1 && dig[n - s] != c) {
      cout << -1 << endl;
      return 0;
    }
    dig[n - s] = c;
  }
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    if (dig[i] > 0) {
      ans += dig[i] * int(pow(10, i));
    }
    if (dig[i] == 0 && (i + 1) == n) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans == 0 && n != 1) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
