#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  int guess[3] = {-1, -1, -1};
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (guess[s] == -1) {
      guess[s] = c;
    } else if (guess[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (guess[0] == -1 || n > 1 && guess[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < (n); i++) {
    ans *= 10;
    ans += guess[i] == -1 ? 0 : guess[i];
  }
  cout << ans << endl;
}
