#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<bool> w(n);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (!w[s - 1]) {
      a[s - 1] = c;
      w[s - 1] = true;
    } else {
      if (a[s - 1] == c) {
        continue;
      } else {
        cout << -1;
        return 0;
      }
    }
  }
  if (n == 1) {
    if (m == 0) {
      cout << -1;
      return 0;
    }
  }
  if (n == 1) {
    if (a[0] == 0) {
      cout << 0;
      return 0;
    }
  }
  if (a[0] == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cout << a[i];
  }
  return 0;
}
