#include <bits/stdc++.h>
using namespace std;
int n, m;
int guessNum() {
  vector<int> nums(n);
  for (int i = 0; i < n; ++i) nums[i] = -1;
  for (int i = 0; i < m; ++i) {
    int s, c;
    cin >> s >> c;
    if (s > n)
      return -1;
    else if (n > 1 && s == 1 && c == 0)
      return -1;
    else if (nums[s - 1] == -1)
      nums[s - 1] = c;
    else if (nums[s - 1] != -1 && c == nums[s - 1])
      continue;
    else
      return -1;
  }
  string ans = "";
  for (int i = 0; i < n; ++i) {
    if (nums[i] == -1 && i != 0) {
      ans += to_string(0);
      continue;
    }
    ans += to_string(nums[i]);
  }
  int a;
  stringstream ss;
  ss << ans;
  ss >> a;
  return a;
}
int main() {
  cin >> n >> m;
  int ans = guessNum();
  cout << ans << endl;
  return 0;
}
