#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const int INF = 1000000000;
int power(int a, int b) {
  int ans = 1;
  while (b > 0) {
    ans = ans * a;
    b--;
  }
  return ans;
}
int rth_digit(int x, int r) {
  int num_of_dig = 0, y = x;
  while (y) {
    num_of_dig++, y /= 10;
  }
  if (x == 0) num_of_dig = 1;
  r = num_of_dig - r;
  return (x / power(10, r)) % 10;
}
int main() {
  int n, m;
  cin >> n >> m;
  int upper_limit = power(10, n), low_limit = power(10, n - 1);
  int ans = -1;
  vector<pair<int, int> > cond;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    cond.push_back({a, b});
  }
  for (int i = low_limit; i < upper_limit; i++) {
    bool flag = true;
    for (auto p : cond) {
      if (rth_digit(i, p.first) != p.second) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
