#include <bits/stdc++.h>
using namespace std;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int INF = 1e9;
const long long LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const long long mod = 1000000007;
int n, m;
bool d[4];
int dd[4];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  bool f = true;
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      f = false;
    } else if (d[s] && dd[s] != c) {
      f = false;
    } else {
      d[s] = true;
      dd[s] = c;
    }
  }
  if (f) {
    for (int i = (1); i < (int)(n + 1); i++) {
      if (d[i])
        cout << dd[i];
      else
        cout << (i == 1 ? 1 : 0);
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
