#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int up = 1;
  for (int i = 0; i < (int)(n); i++) up *= 10;
  vector<vector<int>> J(n, vector<int>(2));
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> J[i][0] >> J[i][1];
  }
  for (int i = 0; i < (int)(up + 1); i++) {
    if (i == 1000) cout << -1 << endl;
    string x = to_string(i);
    if (n != x.size())
      continue;
    else {
      bool j = 1;
      for (int i = 0; i < (int)(m); i++)
        if (x.at(J[i][0] - 1) != J[i][1]) j = 0;
      if (j) {
        cout << i << endl;
        break;
      }
    }
  }
}
