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