#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int solve1() {
  int n, m, ans = 0;
  bool exist = true;
  cin >> n >> m;
  vector<int> number(n);
  for (ll i = 0; i < m; i += 1) {
    int s, c;
    cin >> s >> c;
    --s;
    if (number[s] != 0 && number[s] != c) {
      exist = false;
    } else {
      number[s] = c;
    }
  }
  if (exist) {
    for (ll i = 0; i < (int)number.size(); i += 1) {
      ans += number[i] * pow(10, n - i - 1);
    }
    if (((int)to_string(ans).length()) != n) {
      ans = -1;
    }
  } else {
    ans = -1;
  }
  return ans;
}
int main(void) {
  cout << solve1() << endl;
  return 0;
}
