#include <bits/stdc++.h>
using namespace std;
inline void logger() { cout << endl; }
template <typename A, typename... B>
void logger(const A& a, const B&... b) {
  cout << a << " , ";
  logger(b...);
}
const long long MOD = 1000000007;
const long long MOD9 = 998244353;
const long long INF = MOD * MOD;
const int MAX = 100005;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> num(n);
  for (int(i) = 0; (i) < (n); (i)++) num[i] = -1;
  for (int(i) = 0; (i) < (m); (i)++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0 && n != 1) {
      cout << (-1) << endl;
      return 0;
    }
    if (num[s] != -1 && num[s] != c) {
      cout << (-1) << endl;
      return 0;
    }
    num[s] = c;
  }
  int ans = 0;
  for (int(i) = 0; (i) < (n); (i)++) {
    if (num[i] == -1) {
      if (i == 0)
        num[i] = 1;
      else
        num[i] = 0;
    }
    ans += num[i] * pow(10, n - i - 1);
  }
  cout << (ans) << endl;
}
