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