#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9 + 7;
const int INF = 1e9;
const int MAX = 1e6;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> d(n + 1, -1);
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (n > 1 and s == 1 and c == 0) {
      flag = false;
      break;
    }
    if (d[s] == -1)
      d[s] = c;
    else if (d[s] != c) {
      flag = false;
      break;
    }
  }
  if (flag) {
    for (int i = 0; i < n + 1; i++) {
      if (i == 0) continue;
      if (d[i] == -1)
        printf("%d", 0);
      else
        printf("%d", d[i]);
    }
    printf("\n");
  } else {
    printf("%d\n", -1);
    ;
  }
}
