#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(const T& x) {
  cout << x << endl;
}
template <class T, class... A>
void print(const T& first, const A&... rest) {
  cout << first << " ";
  print(rest...);
}
struct PreMain {
  PreMain() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} premain;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> d(N, -1);
  for (int(i) = 0; (i) < (int)(M); ++(i)) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s >= N) {
      print(-1);
      return 0;
    }
    if (d[s] == -1) {
      d[s] = c;
    } else {
      if (d[s] != c) {
        print(-1);
        return 0;
      }
    }
  }
  if (N == 1) {
    print(d[0]);
    return 0;
  }
  if (d[0] == 0) {
    print(-1);
    return 0;
  }
  int ans = 0;
  for (int(i) = 0; (i) < (int)(N); ++(i)) {
    int x;
    if (i == 0) {
      x = d[i] != -1 ? d[i] : 1;
    } else {
      x = d[i] != -1 ? d[i] : 0;
    }
    ans = ans * 10 + x;
  }
  print(ans);
  return 0;
}
