#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
  int n, m, s[6] = {}, c[6] = {}, num[n] = {};
  cin >> n >> m;
  rep(i,m){
    cin >> s[i] >> c[i];
  }
  rep(i,m){
    if(num[s[i] - 1] != 0){
      if(num[s[i] - 1] > c[i]){
        num[s[i] - 1] = c[i];
      }
    }
  }
  int ans = 0, a = 100;
  rep(i,n){
    ans += num[i] * a;
    a /= 10;
  }
  if(ans >= 0 && ans <= 999){
    cout << ans << endl;
  }else{
    cout << -1 << endl;
  }
  return 0;
}