#include <bits/stdc++.h>
using namespace std;
const long long int inf = (long long int)2e18;
const int mod = 1e9 + 7;
bool overflow(long long int a, long long int b) {
  if (a <= (inf + b - 1) / b) return false;
  return true;
}
string tostring(int x) {
  string s;
  while (x) {
    s.push_back((char)(x % 10 + 48));
    x /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, i, j;
  cin >> n >> m;
  vector<pair<int, int> > v(m);
  for (i = 0; i < m; i++) {
    cin >> v[i].first >> v[i].second;
  }
  int x;
  if (n == 1)
    x = 1;
  else if (n == 2)
    x = 10;
  else if (n == 3)
    x = 100;
  for (i = x; i < 10 * x; i++) {
    string s = tostring(i);
    for (j = 0; j < m; j++) {
      if (s[v[j].first - 1] != 48 + v[j].second) break;
    }
    if (j == m) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
}
