#include <bits/stdc++.h>
using namespace std;
struct data {
  long long s, c;
};
bool cmp(const data& m, const data& n) { return m.s < n.s; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> dig(n, -1);
  int ok = 1, ans = 0;
  for (int(i) = (0); (i) < (m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (dig[s] != -1) {
      if (dig[s] != c) {
        ok = 0;
        break;
      } else {
        dig[s] = c;
        ok = 1;
      }
    } else {
      dig[s] = c;
      ok = 1;
    }
  }
  if (dig[0] == -1) dig[0] = 1;
  if (dig[1] == -1) dig[1] = 0;
  if (dig[2] == -1) dig[2] = 0;
  if (n == 3) {
    ans = dig[0] * 100 + dig[1] * 10 + dig[2];
  } else if (n == 2)
    ans = dig[0] * 10 + dig[1];
  else
    ans = dig[0];
  int buf = 1;
  if (n > 1 && dig[n - 2]) buf = 2;
  if (n > 2 && dig[n - 3]) buf = 3;
  if (ok && buf == n)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
