#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
const long long INFLL = 1LL << 60;
const int INFI = 1000000000;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(N, -1);
  int ans = -2;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v[s] == -1)
      v[s] = c;
    else if (v[s] != c)
      ans = -1;
  }
  if (ans == -2) {
    ans = 0;
    for (int i = 0; i < N; i++) {
      if (v[i] == -1)
        continue;
      else
        ans += v[i] * pow(10, N - i - 1);
    }
    if (v[0] == -1 || v[0] == 0) ans += 1 * pow(10, N - 1);
  }
  if (N == 1 && (v[0] == 0 || v[0] == -1)) ans = 0;
  cout << ans << endl;
}
