#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, -1);
  for (ll i = 0; i < m; i += 1) {
    int s, c;
    cin >> s >> c;
    --s;
    if (number[s] != -1 && number[s] != c) {
      exist = false;
    } else if (n > 1 && s == 0 && c == 0) {
      exist = false;
    } else {
      number[s] = c;
    }
  }
  if (exist) {
    if (n > 1 && number[0] == -1) {
      number[0] = 1;
    }
    for (ll i = 0; i < n; i += 1) {
      if (i > 0 && number[i] == -1) {
        number[i] = 0;
      }
      ans += number[i] * pow(10, n - 1 - i);
    }
  } else {
    ans = -1;
  }
  return ans;
}
int main(void) {
  cout << solve1() << endl;
  return 0;
}
