#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s, c, ans = -1;
  cin >> N >> M;
  vector<int> a(3, -1);
  for (int i = 0; i < (M); i++) {
    cin >> s >> c;
    if (a[s - 1] != -1) {
      if (a[s - 1] == c)
        continue;
      else {
        cout << "-1" << endl;
        return 0;
      }
    }
    if (N != 1 && (s == 1 && c == 0)) {
      cout << "-1" << endl;
      return 0;
    } else {
      a[s - 1] = c;
    }
  }
  ans = 0;
  for (int i = 0; i < (N); i++) {
    if (a[i] == -1) a[i] = 0;
    ans += a[i];
    if (i != N - 1) ans *= 10;
  }
  cout << ans << endl;
  return 0;
}
