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