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