#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int Max = 1005;
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> su(m);
  for (int j = 0; j < m; j++) {
    cin >> su[j].first >> su[j].second;
    su[j].first--;
  }
  for (int i = 0; i < Max; i++) {
    vector<int> aa(n);
    int w = 1;
    for (int d = 0; d < n; d++) w *= 10;
    if (i >= w) continue;
    int j = 0;
    int t = i;
    int gg = 0;
    while (t) {
      aa[j] = t % 10;
      t /= 10;
      j++;
    }
    if (j != n) continue;
    reverse(aa.begin(), aa.end());
    bool ok = true;
    for (int q = 0; q < m; q++) {
      if (aa[su[q].first] != su[q].second) ok = false;
    }
    if (ok) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
