#include <bits/stdc++.h>
using namespace std;
const int MAX = 5;
pair<int, int> s[5 + 1];
int main() {
  int n, m;
  cin >> n >> m;
  for (int j = 1; j <= m; ++j) {
    cin >> s[j].first >> s[j].second;
  }
  for (int i = 0; i < 1e3; ++i) {
    int len = 1;
    if (i >= 10) len++;
    if (i >= 100) len++;
    int find = false;
    for (int j = 1; j <= m; ++j) {
      if (len != n) {
        find = false;
        break;
      }
      int k = i;
      if (len - s[j].first < 0) {
        find = false;
        break;
      }
      int div = pow(10, len - s[j].first);
      int r = k / div % 10;
      if (r != s[j].second) {
        find = false;
        break;
      }
      find = true;
    }
    if (find) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
