#include <bits/stdc++.h>
using namespace std;
void fail() { cout << -1 << endl; }
int main() {
  int n, m;
  int sc[3] = {-1, -1, -1};
  cin >> n >> m;
  int s, c;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if ((sc[s - 1] != -1 && sc[s - 1] != c) || (n < s)) {
      fail();
      return 0;
    }
    sc[s - 1] = c;
  }
  if (n > 1 && (sc[0] == 0 || sc[0] == -1)) {
    fail();
    return 0;
  }
  int p = 1;
  for (int i = 0; i < n - 1; ++i) p *= 10;
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    int x = sc[i] == -1 ? 0 : sc[i];
    ans += x * p;
    p /= 10;
  }
  cout << ans << endl;
  return 0;
}
