#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tt = 1;
  while ((tt)--) {
    long long n, m;
    cin >> n >> m;
    vector<long long> s(m), c(m);
    vector<long long> ans(n, 0);
    long long f = 0;
    for (long long i = 0; i < (m); ++i) {
      cin >> s[i] >> c[i];
      if (ans[s[i] - 1] == 0)
        ans[s[i] - 1] = c[i];
      else if (ans[s[i] - 1] != c[i]) {
        f = 1;
      }
    }
    if (f) {
      cout << -1 << '\n';
    } else {
      long long i = 0, cnt = 0;
      while (ans[i] == 0) {
        i++;
        cnt++;
      }
      if (cnt > 1) {
        f = 1;
        cout << -1 << '\n';
      } else {
        long long temp = 0;
        for (long long i = 0; i <= ((long long)(ans).size() - 1); ++i) {
          temp = temp * 10 + ans[i];
        }
        cout << temp << '\n';
      }
    }
  }
}
