#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
int main() {
  int n, m, s, c;
  cin >> n >> m;
  string r = string(3, ' ');
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if (n != 1 && s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (r[s - 1] != ' ') {
      if (c == r[s - 1] - '0') continue;
      cout << -1 << endl;
      return 0;
    }
    r[s - 1] = (char)('0' + c);
  }
  for (int i = 0; i < (n); ++i) {
    if (r[i] == ' ') r[i] = '0';
  }
  cout << stoi(r) << endl;
  return 0;
}
