#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  vector<int> d(3, -1);
  for (int i = 0; i < (int)m; ++i) {
    int s, c;
    cin >> s >> c;
    if (d[s - 1] != -1 && d[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
    d[s - 1] = c;
  }
  if (n > 1 && d[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1) {
    cout << d[0] << endl;
  } else if (n == 2) {
    for (int i = 0; i < (int)2; ++i) {
      if (d[i] == -1) {
        if (i == 0)
          cout << 1;
        else
          cout << 0;
      } else
        cout << d[i];
    }
    cout << endl;
  } else {
    for (int i = 0; i < (int)3; ++i) {
      if (d[i] == -1) {
        if (i == 0)
          cout << 1;
        else
          cout << 0;
      } else
        cout << d[i];
    }
    cout << endl;
  }
  return 0;
}
