#include <bits/stdc++.h>
const int INF = 2147483647;
const long long int MOD = 1000000007;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int init = n == 1 ? 0 : 1;
  for (int i = 0; i < n - 1; i++) {
    init *= 10;
  }
  int end = init * 10;
  vector<pair<int, int>> sc(m);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    sc[i] = make_pair(n - s, c);
  }
  for (int target = init; target < end; target++) {
    bool ok = true;
    for (int i = 0; i < m; i++) {
      int tmp = target;
      for (int j = 0; j < sc[i].first; j++) {
        tmp /= 10;
      }
      if ((tmp % 10) != sc[i].second) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << target << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
