#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1000000000;
const long long MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<int> num(n, -1);
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    if (num[n - s] == -1 || num[n - s] == c)
      num[n - s] = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < (1000); ++i) {
    if (!(pow(10, n - 1) <= i && i < pow(10, n))) continue;
    bool e = true;
    for (int d = 0; d < (n); ++d) {
      e = e && (num[d] == (i / (int)pow(10, d) % 10) || num[d] == -1);
    }
    if (e) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
