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